1

I have a XSD that defined various complex types, which contains another complex type. The issue is that the inner complex type are exactly the same, but they are not defined as separated type, and therefore I have an inner classes for each top level class. The XSD is as follows:

<xs:complexType name="DOCTRACKTCSCREATEType">
    <xs:sequence>
        <xs:element name="DESCRIPTION" type="xs:string" minOccurs="0"/>
        <xs:element name="gATTRIBNAME" minOccurs="0">
            <xs:complexType>
                <xs:sequence>
                    <xs:element name="mATTRIBNAME" minOccurs="0" maxOccurs="unbounded">
                        <xs:complexType>
                            <xs:sequence>
                                <xs:element name="ATTRIBNAME" type="xs:string" minOccurs="0"/>
                                <xs:element name="ATTRIBVALUE" type="xs:string" minOccurs="0"/>
                            </xs:sequence>
                            <xs:attribute name="m" type="xs:positiveInteger"/>
                        </xs:complexType>
                    </xs:element>
                </xs:sequence>
                <xs:attribute name="g" type="xs:positiveInteger"/>
            </xs:complexType>
        </xs:element>
    <xs:attribute name="id" type="xs:string"/>
</xs:complexType>

<xs:complexType name="DOCTRACKType">
    <xs:sequence>
        <xs:element name="REFERENCE" type="xs:string" minOccurs="0"/>
        <xs:element name="gATTRIBNAME" minOccurs="0">
            <xs:complexType>
                <xs:sequence>
                    <xs:element name="mATTRIBNAME" minOccurs="0" maxOccurs="unbounded">
                        <xs:complexType>
                            <xs:sequence>
                                <xs:element name="ATTRIBNAME" type="xs:string" minOccurs="0"/>
                                <xs:element name="ATTRIBVALUE" type="xs:string" minOccurs="0"/>
                            </xs:sequence>
                            <xs:attribute name="m" type="xs:positiveInteger"/>
                        </xs:complexType>
                    </xs:element>
                </xs:sequence>
                <xs:attribute name="g" type="xs:positiveInteger"/>
            </xs:complexType>
        </xs:element>
    <xs:attribute name="id" type="xs:string"/>
</xs:complexType>

So both define an identical type gATTRIBNAME. I cannot change the XSD, but is there any other way I can have them create the same java class?

Jose L Martinez-Avial
  • 2,191
  • 4
  • 28
  • 42

1 Answers1

0

It seems that JAXB makes this difficult, presumably because it considers the two anonymous complex types different and really doesn't want to let you map them to the same class, even with customized bindings.

Maybe you'd want to try something like having them both implement a common interface? Last I checked, this was only possible through various extensions and plugins, (but some of these are in the RI itself so availability shouldn't be an issue). Here's an older post for example, and you might find more recent ones.

If you do try to proceed with customized bindings, somehow, one other related thought.. you might find the setting <jxb:globalBindings localScoping="toplevel"/> useful for generating top-level rather than inner classes. This opens up some other possibilities for collisions, so possibly not..but FYI.

Hope that helps.. would be interested to hear a better answer.

Community
  • 1
  • 1
Scott Kurz
  • 4,985
  • 1
  • 18
  • 40