So, I'm attempting to read through a modest-sized XML document. It's structured like so:
<project identifier="project1">
<author>Joe Smith</author>
<author2>Rick Jones</author2>
<path>projects/internal/project2</path>
<version>1.51</version>
</project>
<project identifier="project2">
<author>Terry Chimes</author>
<author>Janie Jones</author>
<path>projects/external/project2</path>
<version>19.77</version>
</project>
... and so on, for several hundred projects.
I'm using Qt5.10's QXmlStreamReader, which may have been created (or documented) by sadists.
I can find each project by using xmlReader.readNextStartElement - or by reading tag-by-tag until I find one with internal attributes (only project tags have attributes in this file).
But as soon as I read one of these parent element, the QXmlStreamReader sucks up every tag up to its closing </project> tag. The problem is that I need to get at some of that data, in this case, what's inside the <path></path> tags.
I can retrieve all the slurped-up data with xmlReader.readElementText(QXmlStreamReader::IncludeChildElements, but that's just one big data dump without the tags.
Does anyone know how I can "rewind" and read the internal tags? Or stop the stream reader from lurching forward and sucking up all the data?
The most likely explanation is that you are doing something wrong,
QXmlStreamReadershould not skip inner elements when parsing the document. You haven't provided any source code of yours so it's impossible to tell what exactly you've done wrong.Here's my code sample which works perfectly on the example very similar to yours with Qt 5.9.2 on macOS 10.13.2:
Here's the slightly modified example of yours which I'm feeding to this sample program:
What I added to your sample is XML version/encoding declaration + high-level
bodytag to preventQXmlStreamReaderfrom thinking the firstprojecttag is the root element for the entire document. I also changed the path for the first project to make it different from the second project's one.And here's the output I got: