Skip to main content

xjc class generation: how to force XMLRootElement on a XSD element?

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
1 reply [Last post]
erikvaningen
Offline
Joined: 2010-06-15

I have generated classes with XJC from a set of 55 xsd files:
http://www.fao.org/figis/sdmx/sdmx21xsd/index.html

The generation of classes with XJC runs fine. The problem is that the class generated for GenericData does not have the @XMLRootElement annotation.
My questions are
(1) Why does GenericData not have a @XMLRootElementAnnotation?
(2) How can I force GenericData having the @XMLRootElement annotation?

The xjb binding file has, amongs others, this definition:
<jaxb:globalBindings xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
generateIsSetMethod="false" generateElementClass="true">
<xjc:simple />
</jaxb:globalBindings>

One of the xsd's,
http://www.fao.org/figis/sdmx/sdmx21xsd/SDMXMessage.xsd , has the element GenericData:
<xs:element
name="GenericData"
type="GenericDataType">
</xs:element>

GenericDataType is used by GenericData and by GenericTimeSeriesDataType:
<xs:complexType
name="GenericTimeSeriesDataType">
<xs:complexContent>
<xs:restriction
base="GenericDataType">
................................
</xs:restriction>
</xs:complexContent>
</xs:complexType>

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
fnl
Offline
Joined: 2006-08-11

I had the same problem, and found the solution here:
http://hirenscafe.blogspot.com/2008/04/jaxbxmlrootelement.html