属性组 - 属性 "Value" 已定义。使用 <jaxb:property> 来解决这个冲突

ATTRIBUTE GROUP - Property "Value" is already defined. Use <jaxb:property> to resolve this conflict

问题陈述

我定义了以下内容XSD:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xc="XmlCache" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:import namespace="XmlCache" schemaLocation="mdml/com/mycompany/mds/mdml/schema/xc.xsd"/>
    <xs:element name="MarketData">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="xc:XmlCache" minOccurs="0" maxOccurs="1"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

元素 xc:XmlCache 在文件 mdml/com/mycompany/mds/mdml/schema/xc.xsd 中定义。

我想基于此 XSD 生成 Java 类,使用 jaxb(使用插件 jaxb2-maven-plugin)。

错误

我在编译过程中不断收到以下错误:

[ERROR] jar:file:/C:/Users/miannizzotto/.m2/repository/com/sun/xml/bind/jaxb-xjc/2.1.13/jaxb-xjc-2.1.13.jar!/com/sun/xml/xsom/impl/parser/datatypes.xsd[14,33] com.sun.istack.SAXParseException2; systemId: jar:file:/C:/Users/miannizzotto/.m2/repository/com/sun/xml/bind/jaxb-xjc/2.1.13/jaxb-xjc-2.1.13.jar!/com/sun/xml/xsom/impl/parser/datatypes.xsd; lineNumber: 14; columnNumber: 33; Property "Value" is already defined. Use <jaxb:property> to resolve this conflict.

其次是

[ERROR] file:/D:/v3.1.build.dev.asset.x.91253.5.4.dev/component/legacy/sdk/product-api/api/src/main/xsd/mdml/com/mycompany/mds/mdml/schema/xc.xsd[57,63] com.sun.istack.SAXParseException2; systemId: file:/D:/v3.1.build.dev.asset.x.91253.5.4.dev/component/legacy/sdk/product-api/api/src/main/xsd/mdml/com/mycompany/mds/mdml/schema/xc.xsd; lineNumber: 57; columnNumber: 63; The following location is relevant to the above er

有罪文件的结构

文件mdml/com/mycompany/mds/mdml/schema/xc.xsd非常大,但我只在下面放出有罪的部分(第57行及其树的主要节点):

<?xml version="1.0"?>
<!DOCTYPE xs:schema>
    ...
    <xs:attributeGroup name="valueAtt">
        <xs:attribute name="value" use="optional" form="qualified"/> <!--this is line 57-->
    </xs:attributeGroup>
    ...
</xs:schema>

到目前为止我尝试了什么?

我曾尝试使用我的绑定文件,但以下所有尝试仍然会导致相同的错误。

尝试 1 (灵感来自 this question and its answers

<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
               xmlns:xs="http://www.w3.org/2001/XMLSchema"
               xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
               jaxb:extensionBindingPrefixes="xjc"
               jaxb:version="1.0">

    <jaxb:bindings schemaLocation="../xsd/MarketData.xsd" >

        <jaxb:bindings node=".//xs:attributeGroup[@name='valueAtt']">
            <jaxb:bindings node=".//xs:attribute[@name='value']">
                <jaxb:property name="ValueAttribute"/>
            </jaxb:bindings>
        </jaxb:bindings>

    </jaxb:bindings>
</jaxb:bindings>

(尝试获取 "attributeGroup" 类型的节点 "valueAtt",然后获取 "attribute" 类型的节点 "value",并将其重命名为 "ValueAttribute"。

尝试 2 (灵感来自 this question

<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
               xmlns:xs="http://www.w3.org/2001/XMLSchema"
               xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
               jaxb:extensionBindingPrefixes="xjc"
               jaxb:version="1.0">

    <jaxb:bindings schemaLocation="../xsd/MarketData.xsd" >

        <jaxb:bindings node=".//xs:element[@name=MarketData]/xs:complexType/xs:sequence/xs:element[@ref=XmlCache]">
            <jaxb:bindings node=".//xs:attributeGroup[@name='valueAtt']">
                <jaxb:bindings node=".//xs:attribute[@name='value']">
                    <jaxb:property name="ValueAttribute"/>
                </jaxb:bindings>
            </jaxb:bindings>
        </jaxb:bindings>

    </jaxb:bindings>
</jaxb:bindings>

(与之前尝试的主要区别在于,这里我尝试使用@ref通过引用select节点XmlCache,因为问题发生在另一个XSD).

尝试 3 (仅受直觉的启发,即问题发生在另一个 XSD 中,这只是在我的 XSD 中引用):

<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
               xmlns:xs="http://www.w3.org/2001/XMLSchema"
               xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
               jaxb:extensionBindingPrefixes="xjc"
               jaxb:version="1.0">

    <jaxb:bindings schemaLocation="../xsd/mdml/com/mycompany/mds/mdml/schema/xc.xsd"
    node="//xs:attributeGroup[@name=valueAtt]/xs:attribute[@name=value]">
        <jaxb:property name="ValueAttribute"/>
    </jaxb:bindings>
</jaxb:bindings>

我做错了什么?有人可以帮忙吗?

最后,解决方案如下:

<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
               xmlns:xs="http://www.w3.org/2001/XMLSchema"
               xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
               jaxb:extensionBindingPrefixes="xjc"
               jaxb:version="1.0">

    <jaxb:bindings schemaLocation="../xsd/mdml/com/mycompany/mds/mdml/schema/xc.xsd"
    node="//xs:attributeGroup[@name='valueAtt']/xs:attribute[@name='value']">
        <jaxb:property name="ValueAttribute"/>
    </jaxb:bindings>
</jaxb:bindings>

基本上是我的尝试 3,将属性名称用单引号括起来。