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 call readElementText() in line 441 you move your "cursor" beyond the start element so you can't read the attributes any more.

  • Thank you, @VRonin !
    That was it !
    I guess I didn't realize readElementText() moves the "cursor" the way it does.

    Thanks a bunch !!

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.