users@jaxb.java.net

Root elements

From: Brian Pontarelli <brian_at_pontarelli.com>
Date: Fri, 18 Feb 2005 11:27:08 -0600

Here's another thing I noticed recently. This is an annoyance with XML
Schema in general, but would be nice to be able to handle it somehow. If
I have a root element whose complex type is defined outside of the
element, JAXB doesn't generate the root element during marshalling. This
is as expected because it has no way of determining what the root
element name is because there could be multiple elements of that type.
Here's a schema example:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
  <xs:complexType name="myRootElementType" mixed="false">
    ...
  </xs:complexType>
  <xs:element name="rootElement" type="myRootElementType"/>
</xs:schema>

I this case, I could possibly use a JAXBElement to tell the marshaller
what name to give the root element, but the JAXB 2.0 version available
right now doesn't support that. Or, additional methods could be added to
the marshaller to support these situations. Or, JAXB just could say,
don't do this!

Thoughts?