users@jaxb.java.net

Re: Marshalling in chunks?

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Thu, 11 Aug 2005 13:01:24 -0700

eguy66_at_optonline.net wrote:
> I realize I can marshall each policy item separately, but is there a way
> to marshall just the start tag of <policies>, marshall each individual
> policy item and then marshall the ending </policies> tag (so that I have
> a complete, valid xml document), without building and keeping all
> policies in memory as a big jaxb collection, and marshalling the entire
> object graph? I'm looking for the logical inverse of the
> Partial-Unmarshalling sample, which works very well for the requestor
> receiving this information.

If you are using JAXB 2.0, this is most easily done by using StAX. You
invoke StAX directly to write <policies>, then you pass that StAX writer
and marshal a policy object individually. You then conclude again by
writing </policies> by using the StAX writer directly. I believe there's
a sample bundled with the distribution package that does this.

With JAXB 1.0, you can still do this, but JAXB 1.0 marshaller doesn't
take StAX writer directly, so you need an adapter to bridge them
together. Look at http://stax-utils.dev.java.net/ and use its
ContentHandler->XMLStreamWriter adapter to do this.


-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com