TiXmlDocument doc("example.xml"); doc.LoadFile(); TiXmlElement* root = doc.FirstChildElement("root"); TiXmlElement* element = root->FirstChildElement("element"); std::string text = element->GetText(); std::cout << text << std::endl;
TiXmlDocument doc("example.xml"); doc.LoadFile(); TiXmlElement* root = doc.FirstChildElement("root"); TiXmlElement* element = root->FirstChildElement("element"); element->LinkEndChild(new TiXmlText("new text value")); doc.SaveFile("example.xml");This code loads an XML file, gets the root element, then gets the first child element under the root. The LinkEndChild method of the TiXmlElement class adds a new child node to the element, which is a TiXmlText object with the new text value. The SaveFile method of the TiXmlDocument class saves the changes back to the original file. Package library: TinyXML-2