that was very useful, thanks
----- Original Message -----
From: "Kohsuke Kawaguchi" <Kohsuke.Kawaguchi_at_Sun.COM>
To: <users_at_jaxb.dev.java.net>
Sent: Friday, August 06, 2004 12:11 AM
Subject: Re: continuous xml streaming
> > just a quick one. I have a socket where I send out continuous
multiple xml documents.
> > my problem is for me to unmarshal the xml at the other end I need to
line terminate, or
> > somehow distinguish where one xml document ends and the next start.
> >
> > is there a simple way of setting that in the marshaller (say
setProperty()), or do I have to call
> > a socketStream.write('\0') at the end of each document?
>
> Technically, the XML rec requires a parser to make sure that nothing
> follows after the end of the root element (except a few things like
> whitespace or comments.)
>
> Thus the following entity is not well-formed and a conforming parser
> must flag an error:
>
> <first-doc> ... </first-doc>
> <second-doc> ... </second-doc>
>
> So in Java terminology, a parser is required by the spec to read until
> the EOF. So you can't use a conforming parser to do what you want to do.
>
> But if you have a non-conforming XML parser that can stop reading the
> stream right at </first-doc>, then you can pass that to the Unmarshaller
> by using the unmarshal(Source) method.
>
>
> Alternatively, what people do in similar case is to print the dummy root
> start tag at the very beginning, like this:
>
> <never-ending-xml-stream>
> <first-doc>...</first-doc>
> <second-doc>...</second-doc>
> ...
>
> Then that's a completely legal XML. See XMPP for this kind of protocol
[1].
> In this way you can unmarshal each "document" quite easily by using a
> pull parser. See the pull parser example bundled in the distribution.
>
> [1] http://www.jabber.org/ietf/draft-ietf-xmpp-core-24.txt
>
> regards,
> --
> Kohsuke Kawaguchi
> Sun Microsystems kohsuke.kawaguchi_at_sun.com
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net