JAXB 和匹配 属性 个名称

JAXB and matching property names

我正在尝试使用 XJC 实用程序从 XSD 文件生成 classes。它工作正常,除非查看我生成的 class 我得到:

* You are getting this "catch-all" property because of the following reason: 
* The field name "Products" is used by two different parts of a schema. See: 
* LINE 16 of FILENAME.xsd
* line 15 of FILENAME.xsd

查看 xml:

编辑 - 添加名称空间定义

...
xmlns:def="http://www.host.com/DEFResponse" 
xmlns:abc="http://www.host.com/ABCResponse"
...
<xsd:import namespace="http://www.host.com/ABCResponse" schemaLocation="ABCXMLResponse.xsd"/>
<xsd:import namespace="http://www.host.com/DEFResponse" schemaLocation="DEFXMLResponse.xsd"/>
...
<xsd:choice minOccurs="0">
    <xsd:element name="HostResponse" type="xsd:string"/>
    <xsd:element ref="abc:Products"/>
    <xsd:element ref="def:Products"/>
</xsd:choice>

如何使用绑定告诉它创建两个属性,一个称为 ABCProducts,一个称为 DEFProducts?

我的以下尝试无效:

<jaxb:bindings schemaLocation="FILENAME.xsd">
    <jaxb:bindings node="//xs:choice">
        <jaxb:bindings node=".//xs:attribute[@ref='abc:Products']">
           <jaxb:property name="ABCProducts"/>
        </jaxb:bindings>
        <jaxb:bindings node=".//xs:attribute[@ref='def:Products']">
            <jaxb:property name="DEFProducts"/>
        </jaxb:bindings>
    </jaxb:bindings>
</jaxb:bindings>

我可能做错了什么?

<xsd:element ref="abc:Products"/>
<xsd:element ref="def:Products"/>

abc:Productsdef:Products 是两个 xsd 元素,在您的 xsd 中您定义了 xsd: 前缀而不是 xs: ...所以改变绑定文件如下。

<jaxb:bindings schemaLocation="FILENAME.xsd">
    <jaxb:bindings node="//xsd:choice">
        <jaxb:bindings node="//xsd:element[@ref='abc:Products']">
           <jaxb:property name="ABCProducts"/>
        </jaxb:bindings>
        <jaxb:bindings node="//xsd:element[@ref='def:Products']">
            <jaxb:property name="DEFProducts"/>
        </jaxb:bindings>
    </jaxb:bindings>
</jaxb:bindings>

原来还需要绑定xml:

xmlns:def="http://www.host.com/DEFResponse" 
xmlns:abc="http://www.host.com/ABCResponse"

待定义以使选择生效。

<jaxb:bindings node=".//xs:attribute[@ref='abc:Products']">
       <jaxb:property name="ABCProducts"/>
    </jaxb:bindings>
    <jaxb:bindings node=".//xs:attribute[@ref='def:Products']">
        <jaxb:property name="DEFProducts"/>
    </jaxb:bindings>