[Interest] QXmlStreamReader: Processing multiple documents from QTcpSocket

Sze Howe Koh szehowe.koh at gmail.com
Sun Dec 8 12:57:13 CET 2013


Hello,

For a networked app, I created an XML-based communications protocol
over TCP (a bit like SOAP).

At first, I let QXmlStreamReader read directly from QTcpSocket. When
an EndDocument token is found, I'd call QXmlStreamReader::clear() and
setDevice(), to wait for the next message from the same socket.

This arrangement worked really well initially. However, I noticed that
if 2 messages were sent in quick succession, the end of the 1st XML
document and the start of the 2nd document would be received as a
single chunk of text. The result is an "XML declaration not at start
of document" error (or "Extra content at end of document", if the XML
declaration was omitted).

The only way I can think of around this problem is to parse the data
from the QTcpSocket, delimit it manually, then pass a single XML
document into QXmlStreamReader. This requires me to implement a
minimal XML parser myself though -- is there a nicer way?

It would be great if QXmlStreamReader can play nicely with data
streamed over a network. Would it be reasonable to ask for an option
that lets QXmlStreamReader receive multiple documents during its
lifetime?


Regards,
Sze-Howe



More information about the Interest mailing list