JAXB - 财产“价值”已定义。使用< jaxb:property>解决这个冲突 [英] JAXB - Property "Value" is already defined. Use <jaxb:property> to resolve this conflict

查看:226
本文介绍了JAXB - 财产“价值”已定义。使用< jaxb:property>解决这个冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用JAXB生成XML绑定类。

Using JAXB to generate XML binding classes.

架构基于一组遗留XML文件,并包含以下代码段:

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

<xs:complexType name="MetaType">
    <xs:simpleContent>
        <xs:extension base="xs:string">
            <xs:attribute type="xs:string" name="Name" />
            <xs:attribute type="xs:string" name="Scheme" />
            <xs:attribute type="xs:string" name="Value" />
        </xs:extension>
    </xs:simpleContent>
</xs:complexType>

'Value'属性与 xs的'value'属性冲突: string ,代码生成失败并显示错误:

The 'Value' attribute conflicts with the 'value' property of xs:string, and the code generation fails with the error:

com.sun.istack.SAXParseException2: Property "Value" is already defined. Use &lt;jaxb:property> to resolve this conflict. 


推荐答案

答案在于使用JAXB绑定( site-template.xjb ):

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>

XPath表达式定位节点并重命名,从而避免命名冲突。

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

使用此绑定XML文件,生成的Java类最终具有所需的 getValueAttribute()(以及 getValue())。

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

这篇关于JAXB - 财产“价值”已定义。使用&lt; jaxb:property&gt;解决这个冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆