Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

jaxb

xsd

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.

like image 957
Rotem Avatar asked Nov 20 '25 09:11

Rotem


1 Answers

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"/>
like image 99
michael Avatar answered Nov 22 '25 22:11

michael



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!