#include#include int main() { QFile file("example.xml"); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) return -1; QXmlStreamReader reader(&file); while (!reader.atEnd()) { if (reader.isStartElement()) { if (reader.name() == "item") { //parse item element } } reader.readNextStartElement(); } file.close(); return 0; }
#includeIn this example, we use QXmlStreamReader to parse an XML string and search for "name" elements. Each time we find a "name" element, we read its text using the readElementText function. The function readNextStartElement is called at the end of each loop iteration to move the reader to the next start element in the XML stream. Package Library: Qt XML Moduleint main() { QString xmlString = " "; QXmlStreamReader reader(xmlString); while (!reader.atEnd()) { if (reader.isStartElement()) { if (reader.name() == "name") { QString name = reader.readElementText(); qDebug() << "Name: " << name; } } reader.readNextStartElement(); } return 0; } John 30