users@jaxb.java.net

Custom Marshalling

From: John Tracy <junk_at_valenciasystems.com>
Date: Thu, 14 Aug 2003 16:41:21 -0400

I'm trying to write a JAXB app to unmarshall an XML document and
then marshall it back. The catch is that when I marshall it I want to
replace elements of one type with an XML fragment that may contain
one or more elements of other types. The replacement fragment will
be generated dynamically and represented as a String.

I used the implClass attribute of jxb:class to specify that the unmarshaller
should create instances of a custom class when unmarshalling elements
of this type. My intention was to override the default marshalling methods
in this class to output the XML fragment in place of the element. However,
it appears that the XMLSerializer interface that is used for marshalling will
not allow me to 'output' the XML fragment as a simple string. Is this correct?

I understand that, within my custom marshall method, I could unmarshall the
XML fragment then marshall the resultant content-tree but that seems
inefficient given that the String is known to contain well-formed XML that
is valid at the location to which it will be marshalled.

Is there a better way to accomplish this?