PDA

View Full Version : Possilble Bug? QXmlStreamReader



dempsey001
23rd February 2010, 16:38
Has anyone noticed any issues when attempting to parse large xml documents with the QXmlStreamReader. We are developing code that reads a stream of data off of a QTcpSocket. We attach the reader to the socket and walk over the content. At a certain point, when using a large data stream, we see errors dealing with the parsing.

After some digging it looks like the QXmlStreamReader class has an internal buffer of 8192. What we have been able to determine is that once the buffer fills up the reader begins to process that data. The problem seems to happen when the buffer size restriction causes data chopping where the final thing in the buffer might be something like

<tag attribute="value" /><tag attribute="va

Since the tag is not complete here a parser error happens. Does this mean that the streamed documents have to be under 8192? I figured the reader, since its an incremental parser, would have reported a premature end of document error where my ready read would have continued to stream in the rest of the data. This however, does not seem to happen.

The code I'm using is rather involved and for commercial use so I can't post any of it here, hence the no examples.

SABROG
23rd February 2010, 17:25
If you get QXmlStreamReader::PrematureEndOfDocumentError just run QEventLoop and wait more data from socket, when you get data then exit from local QEventLoop and return to while(). If you don't get new data or user abort parsing just quit from QEventLoop with exit code like "QEventLoop::exit(1)", then compare returned value "int errcode = eventLoop.exec();" and just interrupt while().

So you can't resume parsing without QEventLoop, becouse data not arrived.

dempsey001
23rd February 2010, 17:39
There is already an event loop running for the thread. That is not the problem. Also, the problem is that I am NOT getting a premature end of document. My code is already structured in a way that looks for this error code and does a waitForReadyRead on the device associated with the xml reader. As per Qt's documentation calling wait for ready read from within a ready read signal handler is permitted. Doing this will NOT recursively emit the readyRead signal.

Anyway, the end result here seems to be an error in the way that Qt is processes the XML document if the total size of the document exceeds their internal buffer. Since one batch of text I stream over the socket from a test client exceeds that buffer size, the half tag that is at the end of the buffer is then parsed incorrectly. I end up with a parsing error rather than a premature end of document error. Since I can't distinguish between a real parse error and one generated from this apparently code glitch there is no way to take action here.

SABROG
23rd February 2010, 19:46
Wich error you get, QXmlStreamReader::NotWellFormedError? Maybe something wrong with xml data? Restricted characters for example.

I don't think what problem in buffer, becouse my client/server application work few hours with infinite xml stream.