Hello. There is a file with xml-markup.

<?xml version="1.0" encoding="UTF-8"?> <configuration> <connectionStrings /> .... </configuration> 

Using this function, we determine the success of the functions. And for some reason it is impossible to read the file. The correctness of the file path is verified. The file with the xml-extension gave - the result is the same.

 bool Test() { tinyxml2::XMLDocument xml_doc; tinyxml2::XMLError eResult = xml_doc.LoadFile("Web.config"); std::cout << 1 << endl; if (eResult != tinyxml2::XML_SUCCESS) return false; // Здесь возникает ошибка чтения std::cout << 2 << endl; tinyxml2::XMLNode* root = xml_doc.FirstChild(); if (root == nullptr) return false; std::cout << 3 << endl; tinyxml2::XMLElement* element = root->FirstChildElement("configuration"); if (element == nullptr) return false; return true; } 

The question is what am I doing wrong and how can I fix this?

  • Is the xml file really stored in utf-8? Encoding mismatch is one of the most common problems. - Alexander Petrov

1 answer 1

It turned out that this parser needs to specify the full path of the file.

As a result, we get

 tinyxml2::XMLError eResult = xml_doc.LoadFile("C:\\inetpub\\wwwroot\\adku.web\\Web.config"); 

At least after that, everything worked.