QXmlStreamReader::attributes() not consistent ?
-
Greetings, all.
I'm running into an issue using QXmlStreamReader::attributes(). It appears that it may not be recognizing element attributes consistently.
I have assembled an image of the issue which you should be able to see here. At the top left of the image is a QTreeWidget I'm parsing the XML to. At the top right is the raw XML. Below that is the parsing code and Application Output window. The relevant parts are highlighted in yellow.
What I'm finding odd is the section of code that parses the element attributes works in other sections of the XML (the code is a direct copy/paste), which makes me wonder if it's not something with the particular XML tags in question.
Could someone look this over and suggest what may be causing the issue ?
Thanks in advance ! -
The problem is in your algorithm.
attributes()
works only if you are at the start of an element. when you callreadElementText()
in line 441 you move your "cursor" beyond the start element so you can't read the attributes any more.@VRonin said in QXmlStreamReader::attributes() not consistent ?:
The problem is in your algorithm.
attributes()
works only if you are at the start of an element. when you callreadElementText()
in line 441 you move your "cursor" beyond the start element so you can't read the attributes any more.I've spent a lot of hours trying to find a solution for this problem, your solution should the Qt documentation!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! there is nothing in the XMLStreamReader::attributes() or XMLStreamReader::readElementText() saying anything about this interaction!!!!!!
-
@VRonin said in QXmlStreamReader::attributes() not consistent ?:
The problem is in your algorithm.
attributes()
works only if you are at the start of an element. when you callreadElementText()
in line 441 you move your "cursor" beyond the start element so you can't read the attributes any more.I've spent a lot of hours trying to find a solution for this problem, your solution should the Qt documentation!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! there is nothing in the XMLStreamReader::attributes() or XMLStreamReader::readElementText() saying anything about this interaction!!!!!!
@robson-estek said in QXmlStreamReader::attributes() not consistent ?:
your solution should the Qt documentation!
I would argue it is already in the documentation, you just need to read carefully.
Here's for
QXmlStreamReader::attributes()
:Returns the attributes of a StartElement.
And for
QXmlStreamReader::readElementText()
:Convenience function to be called in case a StartElement was read. Reads until the corresponding EndElement and returns all text in-between. In case of no error, the current token (see tokenType()) after having called this function is EndElement.
So yes, you can't read the attributes for a
StartElement
token, after you've moved to theEndElement
token. -
@robson-estek said in QXmlStreamReader::attributes() not consistent ?:
your solution should the Qt documentation!
I would argue it is already in the documentation, you just need to read carefully.
Here's for
QXmlStreamReader::attributes()
:Returns the attributes of a StartElement.
And for
QXmlStreamReader::readElementText()
:Convenience function to be called in case a StartElement was read. Reads until the corresponding EndElement and returns all text in-between. In case of no error, the current token (see tokenType()) after having called this function is EndElement.
So yes, you can't read the attributes for a
StartElement
token, after you've moved to theEndElement
token.@kshegunov true! I guess I was tired and didn't pay enough attention, anyway @VRonin 's explanation made everything more clear.