Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JAXB和匹配的属性名称_Java_Xml_Xsd_Jaxb_Code Generation - Fatal编程技术网

Java JAXB和匹配的属性名称

Java JAXB和匹配的属性名称,java,xml,xsd,jaxb,code-generation,Java,Xml,Xsd,Jaxb,Code Generation,我试图使用XJC实用程序从XSD文件生成类。除了查看生成的类时,它工作正常: * 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 查看

我试图使用XJC实用程序从XSD文件生成类。除了查看生成的类时,它工作正常:

* 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>
。。。
xmlns:def=”http://www.host.com/DEFResponse" 
xmlns:abc=”http://www.host.com/ABCResponse"
...
...
如何使用绑定让它生成两个属性,一个称为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>


我可能做错了什么?

事实证明,绑定xml还需要:

<xsd:element ref="abc:Products"/>
<xsd:element ref="def:Products"/>
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> 


应该使用绑定文件为这些冲突元素指定类名。另外,您是否在XSD中指定了名称空间?我在最后一个代码块中引用了我试图对绑定文件执行的操作。名称空间已定义为:xmlns:def=”“xmlns:abc=“”,但abc和def架构中是否有targetNamespace?如果它们具有不同的名称空间,则不应使用clashYes,两个附加的包含响应XSD都具有targetNamespace,例如:
<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>