#include "pugixml.hpp" using namespace pugi; int main() { xml_document doc; if (!doc.load_file("books.xml")) return -1; for (xml_node book : doc.child("library").children("book")) { std::cout << "Title: " << book.attribute("title").value() << std::endl; } return 0; }
#include "pugixml.hpp" using namespace pugi; int main() { xml_document doc; xml_node person = doc.append_child("person"); person.append_attribute("name") = "John Doe"; xml_node phone1 = person.append_child("phone"); phone1.append_attribute("type") = "home"; phone1.text() = "(123) 456-7890"; xml_node phone2 = person.append_child("phone"); phone2.append_attribute("type") = "work"; phone2.text() = "(987) 654-3210"; doc.save_file("person.xml"); return 0; }In the above examples, we can see that the pugi xml_node library is used extensively to manipulate XML documents. The library is a part of the pugixml package, which is an open-source library available under the MIT license. Pugixml is a small, fast, and modern XML parser designed for easy integration into other projects.