int main(){ //Creating an XML node XmlNode myNode("person"); // creates a node called 'person' myNode.addAttribute("name", "John Doe"); // adds 'name' attribute to the node with value 'John Doe' myNode.addChild("age", "35"); // adds a child node called 'age' with content '35' std::cout << myNode.toString() << std::endl; // converting the node to a string and printing it to console }
int main(){ //Creating an XML document std::string xmlString = ""; XmlDocument xmlDoc; xmlDoc.loadString(xmlString); //selecting nodes XmlNode bookNode = xmlDoc.getChild("library").getChild("book"); std::string title = bookNode.getChild("title").getContent(); std::string author = bookNode.getChild("author").getContent(); std::cout << "Title: " << title << ", Author: " << author << std::endl; } Harry Potter J.K. Rowling
int main(){ //Creating an XML node XmlNode myNode("person"); myNode.addAttribute("name", "John Doe"); std::cout << myNode.toString() << std::endl; //modifying the existing node myNode.setAttribute("name", "Jane Doe"); //changing the 'name' attribute's value to 'Jane Doe' myNode.addChild("age", "37"); //adding a new child node called 'age' with content '37' std::cout << myNode.toString() << std::endl; }Package library: TinyXML