XML:
<?xml version="1.0" encoding="UTF-8"?> <root-element>Test text</root-element>
C++:
#include <rapidxml/rapidxml_utils.hpp> #include <iostream> using namespace rapidxml; using namespace std; int main() { file<> xmlFile("test.xml"); // Create & parse document xml_document<> doc; doc.parse<0>(xmlFile.data()); // Get root node xml_node<> *root = doc.first_node("root-element"); // Print content if(root == nullptr) { cerr << "Element not found!" << endl; } else { // We found the root element cout << root->value() << endl; } }
Build configuration
add_executable(rapidxml-example rapidxml-example.cpp)
Compile using
cmake . make