#include#include int main() { // Open the XML file QFile file("example.xml"); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) return -1; // Create the XML stream reader QXmlStreamReader xml(&file); // Loop through the XML content while (!xml.atEnd() && !xml.hasError()) { // Read the next element xml.readNext(); // Process the element if (xml.isStartElement()) { // Do something with the start element } else if (xml.isEndElement()) { // Do something with the end element } else if (xml.isCharacters()) { // Do something with the character data } } // Close the file file.close(); return 0; }
#includeThis code shows how to create and initialize a QXmlStreamReader using a QString instead of a QFile. The rest of the code is the same as the previous example. Package: Qt libraryint main() { // Create the XML data string QString xmlData = " "; // Create the XML stream reader QXmlStreamReader xml(xmlData); // Loop through the XML content while (!xml.atEnd() && !xml.hasError()) { // Read the next element xml.readNext(); // Process the element if (xml.isStartElement()) { // Do something with the start element } else if (xml.isEndElement()) { // Do something with the end element } else if (xml.isCharacters()) { // Do something with the character data } } return 0; } Some Book John Doe