#include "tinyxml.h" #includeint main() { TiXmlDocument doc("example.xml"); bool loadOK = doc.LoadFile(); if (loadOK) { std::cout << "File Loaded!" << std::endl; TiXmlElement* root = doc.FirstChildElement("root"); TiXmlElement* element = root->FirstChildElement("element"); std::cout << "Attribute name: " << element->Attribute("name") << std::endl; } else { std::cout << "File not found!" << std::endl; } return 0; }
#include "tinyxml.h" #includeThis example demonstrates how to write an XML file using TiXmlDocument. It creates a root element and a child element with an attribute and saves the document to an XML file. The library package for TiXmlDocument is TinyXML.int main() { TiXmlDocument doc; TiXmlElement* root = new TiXmlElement("root"); doc.LinkEndChild(root); TiXmlElement* element = new TiXmlElement("element"); element->SetAttribute("name", "example"); root->LinkEndChild(element); doc.SaveFile("example.xml"); std::cout << "File saved!" << std::endl; return 0; }