I have an InputSource from a socket where XML data is poured. Id like to
interprete each XML data message separatly. But the
DocumentBuilder.parse(InputSource is) won't parse until the socket is
closed (hence when the InputSource is closed)
Anyone can give me some direction to solve this problem please?
Re: DocumentBuilder.parse(InputSource is)
> I have an InputSource from a socket where XML data is poured. Id like
> interprete each XML data message separatly. But the
> DocumentBuilder.parse(InputSource is) won't parse until the socket is
> closed (hence when the InputSource is closed)
If you have full control over both client and server the easiest is
perhaps to use your own protocol to separate each XML message from each
other, for instance by sending how many characters (or bytes) the next
message is. You then just read in that many characters fully into a
buffer and parse that as a complete XML document. ByteArrayOutputStream
and ByteArrayInputStream are your friends here. Alternatively you can
scan for the xml header string and end tag (easy if it is uniqely named,
complicated if it is not) and then extract the section of data including
both into a buffer for parsing.
If your messages are sufficiently simple in structure and generated on
the fly, it may be even easier and less resource using to let the
complete stream be one valid XML stream where each message is a child of
the top level tag. The complete stream can then be parsed using SAX, as
it can handle never-ending-streams just fine. This is good for long
simple messages, but not so good if your messages have a complicated
structure, or if the rest of the application need the messages as a DOM
|All times are GMT. The time now is 12:07 AM.|
Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.