#include "tinyxml2.h" #includeusing namespace tinyxml2; int main() { XMLDocument doc; doc.LoadFile("example.xml"); // Get root element TiXmlElement* root = doc.RootElement(); // Access first child element TiXmlElement* child = root->FirstChildElement(); // Print child element's name std::cout << "First child element: " << child->Value() << std::endl; return 0; }
#include "tinyxml2.h" #includeThis example is similar to the previous one, but instead of accessing only the first child element, it uses FirstChildElement in a loop to access all child elements of the root element. It prints the name of each child element to the console. Both examples use TinyXML-2 library.using namespace tinyxml2; int main() { XMLDocument doc; doc.LoadFile("example.xml"); // Get root element TiXmlElement* root = doc.RootElement(); // Access all child elements for (TiXmlElement* child = root->FirstChildElement(); child != nullptr; child = child->NextSiblingElement()) { std::cout << "Child element: " << child->Value() << std::endl; } return 0; }