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: Wolfgang Hoschek <wolfgang.hoschek AT mac.com>
  • To: 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 12:50:53 -0700

On Oct 20, 2006, at 12:42 PM, Steve Loughran wrote:

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.


Might be a non-issue, but to be precise: NUL may occur for encodings other than ASCII and UTF-8.
In contrast, Consistent Overhead Byte Stuffing (COBS) provides efficient, reliable, unambigous packet framing regardless of packet content.

Wolfgang.




Archive powered by MHonArc 2.6.24.

Top of Page