Rotem
Rotem

Reputation: 2356

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

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

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

Upvotes: 3

Views: 3780

Answers (1)

michael
michael

Reputation: 61

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

Upvotes: 1

Related Questions