#include#include using namespace tinyxml2; int main() { XMLDocument doc; doc.LoadFile("example.xml"); XMLElement* root = doc.FirstChildElement("root"); XMLElement* child = root->FirstChildElement("child"); const char* text = child->GetText(); std::cout << "Text content: " << text << std::endl; return 0; }
#includeThis example uses the pugixml library to load an XML file, select the first "root" node, select the first "child" node under it, and retrieve its text content using the text method. The output should be the text content of the "child" node. Package library: pugixml#include using namespace pugi; int main() { xml_document doc; doc.load_file("example.xml"); xml_node root = doc.child("root"); xml_node child = root.child("child"); std::string text = child.text().as_string(); std::cout << "Text content: " << text << std::endl; return 0; }