Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] reading an xml from a socket

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: "Steve Loughran" <steve.loughran AT gmail.com>
  • Cc: xom-interest AT lists.ibiblio.org
  • Subject: Re: [XOM-interest] reading an xml from a socket
  • Date: Fri, 20 Oct 2006 20:42:16 +0100

On 20/10/06, Wolfgang Hoschek <wolfgang.hoschek AT mac.com> wrote:
XML does not specify an end-of-document marker. Instead, such framing
issues are left to a higher level protocol (e.g. HTTP).

A generic XML parser has no knowledge of the higher level protocol in
use, thus will parse until it hits end-of-stream (EOS). For example,
HTTP/MIME knows where the end of a response occurs, so an InputStream
containing the XML payload derived from a servlet will indicate EOS
at the correct spot. If you're not using a protocol that has framing
built-in, you'll have to roll your own. Here's a simple example:

msg := length payload
length := 4 byte integer (big endian)
payload := sequence of <length> bytes

For are more thorough discussion of framing issues, see [1] and [2].

You could also stick a version number/magic number at the start of the
communication. If the receipient does this it piggybacks on the TCP
ack packet and costs you nothing.

Also, ASCII 0 is a forbidden character in an XML document. So you
could write something that streams out a document and sticks a NUL at
the end. The reciepient relays everything to an XML parser (via a
special Reader), until that NUL gets received, at which point an
end-of-file should be signalled. Result: no need to determine the size
of the message.

-steve




Archive powered by MHonArc 2.6.24.

Top of Page