JAXB - Property “Value” is already defined. Use to resolve this conflict

前端 未结 7 565
再見小時候
再見小時候 2020-11-30 19:01

Using JAXB to generate XML binding classes.

The schema is based on a set of legacy XML files, and includes this snippet:



        
相关标签:
7条回答
  • 2020-11-30 19:57

    The answer lies in making use of JAXB bindings (site-template.xjb):

    <bindings xmlns="http://java.sun.com/xml/ns/jaxb"
              xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
              xmlns:xs="http://www.w3.org/2001/XMLSchema"
              version="2.1">
        <bindings schemaLocation="site-template.xsd" version="1.0">
            <!-- Customise the package name -->
            <schemaBindings>
                <package name="com.example.schema"/>
            </schemaBindings>
    
            <!-- rename the value element -->
            <bindings node="//xs:complexType[@name='MetaType']">
                <bindings node=".//xs:attribute[@name='Value']">
                    <property name="ValueAttribute"/>
                </bindings>
            </bindings>
        </bindings>
    </bindings>
    

    The XPath expressions locate the nodes and renames it, thereby avoiding the naming conflict.

    Using this bindings XML file, the generated Java class ends up having the desired getValueAttribute() (as well as the getValue()).

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