I have this schema:
<xs:element name="document" type="Document/>
<xs:complexType name="Document">
<xs:sequence>
<xs:element name="description" type="xs:string" minOccurs="0"/>
<xs:element name="destination" type="xs:string" minOccurs="0"/>
<xs:element name="tags" type="TagList" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="TagList">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:any processContents="lax" namespace="http://www.example.com/schema/tags"/>
</xs:choice>
</xs:complexType>
This schema supports the following XML:
<document>
<description>the description</description>
<destination>the destination</destination>
<tags>
<tagA>
<propA1>...</propA1>
<propA2>...</propA2>
...
</tagA>
<tagB>
<propB1>...</propB1>
<propB2>...</propB2>
...
</tagB>
...
</tags>
</document>
The list represented by tags
contains 0+ elements of various tag types that are defined in a separate schema.
When I generate the Java classes from this schema with xjc, I get the following output:
public class Document {
private String description;
private String destination;
private TagsList tags;
// getter/setter
}
public class TagsList {
private List<Object> any;
// getter/setter
}
This means I have to type document.getTags().getAny()
to access the tag items. Is there a way to generate a DocumentClass
containing directly the tags
field as a List<Object>
, like this:
public class Document {
private String description;
private String destination;
private List<Object> tags;
// getter/setter
}
Note: changing from choice
to sequence
in TagsList
makes no difference.
Depending how you generate your java classes from XSD, you should try to add one of the existing XEW plugins available (this one is the most advanced at the time writing : https://github.com/dmak/jaxb-xew-plugin)
I recommend you to read the documentation in order to do what you want.
Here is a sample configuration based on the jaxb-tools maven-plugin :
<plugin>
<groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb-maven-plugin</artifactId>
<version>correct version according targeted JAXB api</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<extension>true</extension>
<args>
<arg>-Xxew</arg>
</args>
<plugins>
<plugin>
<groupId>com.github.jaxb-xew-plugin</groupId>
<artifactId>jaxb-xew-plugin</artifactId>
<version>correct version according JAXB api</version>
</plugin>
</plugins>
</configuration>
</execution>
</executions>
</plugin>