Minimales RapidXML-Dateileser-Beispiel
English
Deutsch
XML:
test.xml
<?xml version="1.0" encoding="UTF-8"?>
<root-element>Test text</root-element>C++:
rapidxml-example.cpp
#include <rapidxml/rapidxml_utils.hpp>
#include <iostream>
using namespace rapidxml;
using namespace std;
int main() {
file<> xmlFile("test.xml");
// Dokument erstellen und parsen
xml_document<> doc;
doc.parse<0>(xmlFile.data());
// Root-Knoten abrufen
xml_node<> *root = doc.first_node("root-element");
// Inhalt ausgeben
if(root == nullptr) {
cerr << "Element not found!" << endl;
} else { // Wir haben das Root-Element gefunden
cout << root->value() << endl;
}
}Build-Konfiguration
CMakeLists.txt
add_executable(rapidxml-example rapidxml-example.cpp)Kompilieren mit
build.sh
cmake .
makeCheck out similar posts by category:
C/C++
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow