Details
-
Bug
-
Resolution: Won't Do
-
P3: Somewhat important
-
4.7.0, 5.4.2
-
None
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.