Iterate over XML with QXmlStreamReader
-
Hi Folks,
I have to build a project that process XML files, so I started to learn a bit about Qt XML with QXmlStreamReader, but it seems I'm in trouble. I have a XML files, like this:
<?xml version="1.0" encoding="UTF-8"?>
<project>
<root name="readername">
<proeprty name="hwInputNumber" ...>
<proeprty name="defaultGateway" ...>
<enumeration name="input">
<proeprty name="trigger" ...>
</enumeration>
<enumeration name="output">
<proeprty name="adress" ...>
</enumeration>
</root>
</project>and I wrote some code, that targets to print out the name of the XML nodes and the value of the "name" attribute:
@
QXmlStreamReader reader(&_project);
while (!reader.isEndDocument()) {
reader.readNextStartElement();
qDebug() << reader.name() << reader.attributes().value("name");
reader.skipCurrentElement();
else if(reader.isEndElement()) {
reader.readNextStartElement();
qDebug() << "";
}
}
@It seems that the processing getting into an infinite loop when it reaches the "<proeprty name="trigger" ...>" line under the "enumeration" node.
I guessed that some "step back" should be exist that navigate me to the parent node, but I didn't found such a method in the API reference.
Can anybody help me?
Regards,
Norbert -
Hi,
You should take a look at the Stream Bookmarks example You'll see how to parse an an xml file.
-