I have a wsdl that imports a schema I am trying to resolve xjc naming multiple nested MyElementName classes with the same name - which doesn\'t compile I have created this b
Your XPath:
//xsd:element[@name='AAA']
//xsd:sequence/xsd:element[@name='BBB']
//xsd:element[@name='MyElementName']
Seems to refer to both of your MyElementName
elements since they're both under BBB
. Try to get rid of //
.
//xsd:element[@name='AAA']
/xsd:complexType
/xsd:sequence
/xsd:element[@name='BBB']
/xsd:complexType
/xsd:sequence
/xsd:element[@name='MyElementName']
I think this is the right direction you go. You have to customize your anonymous inner complex types.
JAXB generates one class per one complex type, so I believe you should bind your custom class name to xs:complexType rather than xs:element. Your first XPath refers to the xs:element and I think JAXB does not know how to bind a class to it. Try this binding:
<jaxb:bindings
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
version="2.1">
<jaxb:bindings schemaLocation="MYWSDL.wsdl">
<jaxb:bindings node="//xsd:element[@name='AAAA']//xsd:complexType//xsd:sequence/xsd:element[@name='BBB']//xsd:complexType/xsd:sequence//xsd:element[@name='MyElementName']/xs:complexType">
<jaxb:class name="MyElementName1"/>
</jaxb:bindings>
<jaxb:bindings node="//xsd:element[@name='AAAA']//xsd:sequence/xsd:element[@name='BBB']//xsd:element[@name='MyElementName']//xsd:sequence/xsd:element[@name='CCC']//xsd:sequence/xsd:element[@name='MyElementName']/xsd:complexType">
<jaxb:class name="MyElementName2"/>
</jaxb:bindings>
</jaxb:bindings>
Personally, I prefer using JAXB to XMLBeans. You should be careful with the latter, because when compiling a deeply nested schema it may generate a structure of nested classes impossible to compile due to filename length limitations (usually 255 characters).