how to rename nested classes in jaxb xjc

前端 未结 2 936
面向向阳花
面向向阳花 2020-12-22 01:21

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

相关标签:
2条回答
  • 2020-12-22 01:49

    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.

    0 讨论(0)
  • 2020-12-22 01:56

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

    0 讨论(0)
提交回复
热议问题