Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-25944

QXmlStreamReader::readNextStartElement() works inelegantly with isEndDocument()

    XMLWordPrintable

Details

    • ccd8a496c (dev), 3e2be095e (6.5), ce3ca69dc (6.6), a9fe8dde7 (tqtc/lts-6.2)

    Description

      Hi all,

      I was just debugging a piece of code similar to the attached, and was a little surprised by the behaviour of readNextStartElement(). It seems that if we use readNextStartElement() repeatedly to parse a well-formed XML document, then calling readNextStartElement() after we've read the whole of the XML document sets the error status to QXmlStreamReader::PrematureEndOfDocumentError. This is odd, as the documentation for this error code says:

      "The input stream ended before a well-formed XML document was parsed."

      which, if my understanding of XML + QXmlStreamReader is correct, is untrue in this case!

      I personally think the following behaviour would be more logical: if we attempt to readNextStartElement() after we've already read the entirety of a well-formed XML document, then

      a) readNextStartElement() should return false;
      b) it should not set the error flag for the QXmlStreamReader i.e. hasError() should return false; and
      c) tokenType() should be QXmlStreamReader::EndDocument.

      This would get rid of the incorrect statement that we didn't manage to read a well-formed XML document, and makes the attached program work.

      What do you guys reckon?

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            axelspoerl Axel Spoerl
            simonsj Simon St James
            Votes:
            3 Vote for this issue
            Watchers:
            8 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: