Reputation: 3848
I have an xml file that looks like this:
<RootItem>
<Items>
<Item />
<Item />
<Item />
</Items>
<Values>
<Value />
<Value />
<Value />
</Values>
<AnotherItem />
</RootItem>
I'm using Trang to translate this into a .xsd schema, and using xjc to translate the schema into annotated Java classes (that work smoothly with jaxB to marshal and unmarshall my documents) My only problem is that xjc gives me these classes:
I don't want a "Items" or a "Values" class. How do I format my schema to tell it to ignore the parent element and just make a "List items" object in my RootItem class?
What I want:
Thanks!
Edit: Here's the schema generated by Trang:
<xs:element name="RootItem">
<xs:complexType>
<xs:sequence>
<xs:element ref="Items"/>
<xs:element ref="Values"/>
</xs:sequence>
<xs:element name="AnotherItem" use="required" type="xs:NCName"/>
</xs:complexType>
</xs:element>
<xs:element name="Items">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="Item"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Values">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="Value"/>
</xs:sequence>
</xs:complexType>
</xs:element>
Upvotes: 2
Views: 1305
Reputation: 149037
You can always start from Java classes. You can use @XmlElementWrapper to get the grouping elements "Items" and "Values".
Note: JAXB does not require the object factory. JAXB can leverage metadata on a class like ObjectFactory that is annotated with @XmlRegistry.
Upvotes: 3