Nested elements in XSD cause Illegal class inheritance loop exception in JAXB, how can I properly override the bindings?
You wrote:
<jaxb:bindings node="//xs:element[@name='ArchiveTransferRequest'] /xs:complexType/xs:sequence/xs:element[@name='Contains'] /xs:complexType/xs:sequence/xs:element[@name='Contains']">
I took your XSD and fixed it to make it a legal document. Then I took your XPath expressions, they selected the xs:element
correctly.
There's only one more thing you need to do to make this working: select the xs:complexType
, not the xs:element
, because that is what JAXB uses to create the classes, not the elements.
The following should work:
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="2.1">
<jaxb:bindings schemaLocation="seda_actes.xsd">
<jaxb:bindings node="//xs:element[@name='ArchiveTransferRequest']
/xs:complexType/xs:sequence/xs:element[@name='Contains']
/xs:complexType/xs:sequence/xs:element[@name='Contains']
/xs:complexType">
<jaxb:class name="SecondContains"/>
</jaxb:bindings>
<jaxb:bindings node="//xs:element[@name='ArchiveTransferRequest']
/xs:complexType/xs:sequence/xs:element[@name='Contains']
/xs:complexType/xs:sequence/xs:element[@name='Contains']
/xs:complexType/xs:sequence/xs:element[@name='Contains']
/xs:complexType">
<jaxb:class name="ThirdContains"/>
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
Though it's an old question but just to help others make sure to add the "/xs:complexType" at the end. So instead of below:
<jaxb:bindings node="//xs:element[@name='ArchiveTransferRequest']/xs:complexType/xs:sequence/xs:element[@name='Contains']/xs:complexType/xs:sequence/xs:element[@name='Contains']">
<jaxb:class name="SecondContains"/>
</jaxb:bindings>
It should be as:
<jaxb:bindings node="//xs:element[@name='ArchiveTransferRequest']/xs:complexType/xs:sequence/xs:element[@name='Contains']/xs:complexType/xs:sequence/xs:element[@name='Contains']/xs:complexType">
<jaxb:class name="SecondContains"/>
</jaxb:bindings>