users@jaxb.java.net

Marshalling a content sub-tree

From: Luca Buraggi <lburaggi_at_MATE.IT>
Date: Thu, 06 Mar 2003 05:04:28 -0700

After a first reading of JAXB documentation, it was my opinion that it should be possible to marshal a content tree not only starting from the root node, but also from child node, i.e specifying to the marshal method of the marshaller object a child node as content tree.

Some tests, done using the JAXB beta release, gave good results.

But now, with the JAXB 1.0 FCS things are changed, and I got confused by the tests new behaviour:

1) When unmarshalling a XML file, the resulting content tree contains nodes that sometimes are instances of the xxxxImpl class and sometimes of the xxxxTypeImpl class (xxxx is the name of the schema element from which the xxxxImpl and xxxxTypeImpl have been generated by the JAXB compiler). The rationale of this difference is not clear to me.

2) When trying to marshall any single node of the content tree, the following weird thing happens:
- If the node passed to the marshaller.marshal(node, out) is of type xxxxImpl the generated XML is ok and contains the xxxx element as root element.
- if the node is of type xxxxTypeImpl the XML document is wrong, not well formed, with the root element missing.

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 ?

There is some other way to marshal each single node of a content tree ?