users@jaxb.java.net

Re: How to marshal XML fragments with JAXB

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Fri, 25 Apr 2003 10:36:47 -0700

It currently doesn't have any explicit support for fragment marshalling,
but like you said, you can easily write an XMLFilter that blocks
start|endDocument. In your case, you just need to:

    Marshaller m = jc.createMarshaller();
    m.marshal(myElem, new FragmentFilter(contentHandler));

where FragmentFilter is:

    class FragmentFilter extends XMLFilterImpl {
        FragmentFilter( ContentHandler handler ) {
            setContentHandler(handler);
        }

        public void startDocument() {}
        public void endDocument() {}
    }

Perhaps this could be another example.

regards,
--
Kohsuke KAWAGUCHI                  408-276-7063 (x17063)
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com