Skip parent element of list of objects in XML schema



I'm trying to create XSD schemas for an XML API I am using so that I can generate Java files based on it. The response contains a list of elements wrapped in a parent tag that I really don't care for, but I'm having issues trying to skip making a new complexType just for that parent tag.


The XML is of the following form:



<?xml version='1.0' encoding='UTF-8'?>
<root>
<currentTime>2012-02-12 14:39:12</currentTime>
<result>
<rowset attr1="foo" attr2="bar">
<row name="Some Name" id="238510404"/>
<row name="Some Name" id="238510404"/>
<row name="Some Name" id="238510404"/>
<row name="Some Name" id="238510404"/>
</rowset>
</result>
<cachedUntil>2012-02-12 15:27:00</cachedUntil>
</root>


rowset is the element that I ideally want to turn into a field in the class generated for this document.


Here's the basic schema I am using (it was generated, not handwritten):



<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="currentTime"/>
<xs:element name="result">
<xs:complexType>
<xs:sequence>
<!-- rowset element -->
<xs:element name="rowset">
<xs:complexType>
<xs:sequence>
<xs:element name="row" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="name"/>
<xs:attribute type="xs:int" name="id"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<!-- /rowset element -->
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element type="xs:string" name="cachedUntil"/>
</xs:sequence>
</xs:complexType>
</xs:element>


Using that schema with xjc gets me nested classes all the way down to Root.Result.Rowset, which contains a list of Root.Result.Rowset.Row objects, with the list name being row. I know the name of the rowset element isn't going to change and I do not need the values of its attributes.


Is there a way to get rid of the Rowset object and type and replace them with a List<Row> rowset member in Root.Result (I am fine with naming the new member rowset, though if possible I'd like to change it)?


No comments:

Post a Comment