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

QXmlStreamReader::readElementText() does not recover from PrematureEndOfDocumentErrors

    XMLWordPrintable

Details

    Description

      QXmlStreamReader::readElementText() cannot handle incomplete XML data (as it e.g. happens when reading from a socket).

      Example:

      <tag>Some text<tag>

      Let's assume that we read above XML using a socket, and the current data in the buffer is "<tag>Some ". The parser is on the <tag> start element, i.e. isStartElement() is true. I want to read the element text using QXmlStreamReader::readElementText().

      It returns "Some " and set the stream reader's error() to PrematureEndOfDocumentError.

      Then the remaining data "text<tag>" arrives in the device buffer.

      If I now call readElementText() again, a null string is returned and PrematureEndOfDocumentError is still set. That's because readElementText() does nothing and returns a null string if isStartElement() is false. Thus, there is no way to recover from PrematureEndOfDocumentError using the readElementText() convenience method.

      In my opinion, readElementText() should either

      a) return partial chunks: first call: return "Some " and set PrematureEndOfDocumentError. (like it does now) Second call: return "text" and clear the error.

      or

      b) backtrack to the start element: first call: return a null string and set PrematureEndOfDocumentError Second call: return "Some text" and clear the error.

      Whatever it does, should be documented in the API documentation.

      Attachments

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

        Activity

          People

            Unassigned Unassigned
            frank.osterfeld Frank Osterfeld
            Votes:
            2 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes