开发者

Generate java classes from XSD using intellij (JAXB plugin) that extends existing class file

开发者 https://www.devze.com 2023-03-23 03:58 出处:网络
I have this XSD file: <?xml version=\"1.0\" encoding=\"UTF-8\"?> <xs:schema targetNamespace=\"http://www.example.com/dnavigator\"

I have this XSD file:

<?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开发者_如何学C">

                <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>

I want that the class DynamicNavigator that will be generated, extends the class com.example.MyClass

How can I do it?

Thank you.


JAXB only creates objects for complexTypes, so don't wrap your complexTypes in 'xs:element' tags. Try using 'xs:element ref' within the complexType instead of creating new elements within your complexType. for instance:

<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"/>
0

精彩评论

暂无评论...
验证码 换一张
取 消