users@jaxb.java.net

Re: Marshalling a content sub-tree

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Thu, 06 Mar 2003 11:14:23 -0800

> Should I conclude that my original idea is wrong, and that marshalling a
> content tree is only supported when the root of a previously
> unmarshalled tree is used, or when the content tree has been creaded
> with ObjectFactory,createxxxx() method calls ?

I personally don't think your idea was wrong. It's just that I don't
know what can be done. The problem is that the type objects (those which
don't implement java.xmlx.bind.Element) don't know tag names. So they
always need to be a child of something else to be properly marshalled.


An RI-specific solution is for us to provide a generic "element wrapper",
which you can use like this:

Object myJaxbObject = ....;

if( myJaxbObject instanceof javax.xml.bind.Element )
    marshaller.marshal(myJaxbObject);
else {
    ElementWrapper ew = new ElementWrapper("uri","local",myJaxbObject);
    marshaller.marshal(ew);
}

You still need to give it the element name, though. Does this solve your
problem?


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