我有这个XSD文件:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://www.example.com/dnavigator"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:dn="http://www.example.com/dnavigator"
attributeFormDefault="unqualified"
elementFormDefault="qualified"
jaxb:version="2.0">
<xs:annotation>
<xs:appinfo>
<jaxb:globalBindings enableJavaNamingConventions="true"/>
</xs:appinfo>
</xs:annotation>
<xs:element name="DynamicNavigators">
<xs:complexType>
<xs:sequence>
<xs:element name="DynamicNavigator"
type="dn:DynamicNavigator"
minOccurs="1"
maxOccurs="unbounded">
<xs:annotation>
<xs:documentation>
</xs:documentation>
<xs:appinfo>
<jaxb:property name="DynamicNavigators"/>
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="DynamicNavigator">
<xs:sequence minOccurs="0"
maxOccurs="unbounded">
<xs:element name="example"
type="xs:string"
minOccurs="1"
maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
我想要生成的类DynamicNavigator,扩展类com.example.MyClass
我该怎么做?
谢谢。
答案 0 :(得分:1)
JAXB只为complexTypes创建对象,因此不要将complexTypes包装在'xs:element'标记中。尝试在complexType中使用'xs:element ref',而不是在complexType中创建新元素。例如:
<xs:complexType name="DynamicNavigatorsType">
<xs:sequence>
<xs:element ref="dn:DynamicNavigator" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="DynamicNavigatorType">
<xs:sequence>
<xs:element ref="dn:example"/>
</xs:sequence>
</xs:complexType>
<xs:element name="DynamicNavigator" type="dn:DynamicNavigatorType"/>
<xs:element name="example" type="xs:string"/>