gpt4 book ai didi

java - XJB [错误] 为目标命名空间定义了多个

转载 作者:太空宇宙 更新时间:2023-11-04 07:28:03 27 4
gpt4 key购买 nike

我有多个 XSD 文件,我想对它们运行 XJC 以创建 java 类对象,我将其用于进一步处理。问题:当我运行 XJC 命令时,我的一组 XSD 中的 2 个 XSD 出现问题。 XSD 是:

contactLM.xsd

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:w="http://w.com/xsd"
xmlns="http://w.com/location.contactlm"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
targetNamespace="http://w.com/location.contactlm"
elementFormDefault="qualified" jaxb:version="2.1">
<xsd:annotation>
<xsd:appinfo>
<jaxb:schemaBindings>
<jaxb:package name="location.contactlm"/>
</jaxb:schemaBindings>
</xsd:appinfo>
</xsd:annotation>

<xsd:element name="Contact" type="Contact" nillable="true"/>

<xsd:complexType name="Contact">
<xsd:sequence>
<xsd:element name="RefID" type="xsd:string" nillable="true"
minOccurs="0" gw:type="java.lang.String"/>
</xsd:sequence>
</xsd:complexType>


</xsd:schema>

contactM.xsd

<?xml version="1.0"?>
<xsd:schema
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:w="http://w.com/xsd"
xmlns="http://w.com/location.contactm"
targetNamespace="http://w.com/location.contactm"
elementFormDefault="qualified"
xmlns:ns0="http://w.com/location.contactam"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
jaxb:version="2.1">
<xsd:annotation>
<xsd:appinfo>
<jaxb:schemaBindings>
<jaxb:package name="location.contactm"/>
</jaxb:schemaBindings>
</xsd:appinfo>
</xsd:annotation>
<xsd:import namespace="http://w.com/location.contactam"
schemaLocation="ContactAM.xsd"/>
<xsd:element name="Contact" type="Contact" nillable="true"/>
<xsd:complexType name="Contact">
<xsd:sequence>
<xsd:element name="RefID" minOccurs="0" nillable="true"
type="xsd:string" gw:type="java.lang.String"/>
<xsd:element name="WorkPhone" minOccurs="0" nillable="true"
type="xsd:string" gw:type="java.lang.String"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>

我知道这些 XSD 文件中引用了相同的“联系人”,这是一个问题。所以,我必须编写我的 XJB 文件。我编写了以下 xjb 文件:

<jaxb:bindings
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:gw="http://w.com/xsd"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
xmlns="http://w.com/location.contactlm"

targetNamespace="http://w.com/location.contactlm"
jaxb:version="2.1">

<jaxb:bindings schemaLocation="ContactM.xsd">
<jaxb:bindings node=".//xs:element[@name='Contact']">
<jaxb:class name="ContactM"/>
</jaxb:bindings>
<jaxb:schemaBindings>
<jaxb:package name="location.contactm" />
</jaxb:schemaBindings>
</jaxb:bindings>

<jaxb:bindings schemaLocation="ContactLM.xsd">
<jaxb:bindings node=".//xs:element[@name='Contact']">
<jaxb:class name="ContactCLM"/>
</jaxb:bindings>
<jaxb:schemaBindings>
<jaxb:package name="location.contactlm" />
</jaxb:schemaBindings>
</jaxb:bindings>

</jaxb:bindings>

但是当我这样做时,我收到以下错误:

xjc -d src -b C:\us\binding.xjb C:\us\trunk\shared\


parsing a schema...
346368376 / 346685920 (-1 / -1) (com/sun/tools/internal/xjc/reader/xmlschema/bindinfo/CollectionTypeAttribute$JaxbAccessorF_collectionType/com/sun/tools/internal/xjc/reader/xmlschema/bindinfo/CollectionTyp
eAttribute$JaxbAccessorF_collectionType)
[ERROR] Multiple <schemaBindings> are defined for the target namespace "http://w.com/location.contactm"
line 10 of file:/C:/us/trunk/contact/ContactM.xsd

[ERROR] Another <schemaBindings> is defined here
line 14 of file:/C:/us/trunk/contact/binding.xjb

[ERROR] Multiple <schemaBindings> are defined for the target namespace "http://w.com//trunk/contactlm"
line 5 of file:/C:/us/trunk/contact/ContactLM.xsd

[ERROR] Another <schemaBindings> is defined here
line 23 of file:/C:/us/trunk/contact/binding.xjb

[ERROR] compiler was unable to honor this schemaBinding customization. It is attached to a wrong place, or its inconsistent with other bindings.
line 14 of file:/C:/us/trunk/contact/binding.xjb

[ERROR] (the above customization is attached to the following location in the schema)
line 10 of file:/C:/us/trunk/contact/ContactM.xsd

[ERROR] compiler was unable to honor this schemaBinding customization. It is attached to a wrong place, or its inconsistent with other bindings.
line 23 of file:/C:/us/trunk/contact/binding.xjb

[ERROR] (the above customization is attached to the following location in the schema)
line 2 of file:/C:/us/trunk/contact/ContactLM.xsd

Failed to parse a schema.

我想我可能在 XJB 文件中做错了什么,但我无法解决该问题。请有人帮忙。

最佳答案

您主要需要做的是从 xsd 文件中删除方案绑定(bind)。我已经复制并测试了您的文件并且它有效。不过,我将对 ContactAM 的引用更改为 ContactLM,假设这是一个拼写错误。

这是我的文件:

联系M.xsd

<?xml version="1.0"?>
<xsd:schema
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:gw="http://w.com/xsd"
xmlns="http://w.com/location.contactm"
targetNamespace="http://w.com/location.contactm"
elementFormDefault="qualified"
xmlns:ns0="http://w.com/location.contactam"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
jaxb:version="2.1">
<xsd:annotation>
<xsd:appinfo>
<!-- <jaxb:schemaBindings> -->
<!-- <jaxb:package name="location.contactm"/> -->
<!-- </jaxb:schemaBindings> -->
</xsd:appinfo>
</xsd:annotation>
<xsd:import namespace="http://w.com/location.contactlm"
schemaLocation="ContactLM.xsd"/>
<xsd:element name="Contact" type="Contact" nillable="true"/>
<xsd:complexType name="Contact">
<xsd:sequence>
<xsd:element name="RefID" minOccurs="0" nillable="true"
type="xsd:string" gw:type="java.lang.String"/>
<xsd:element name="WorkPhone" minOccurs="0" nillable="true"
type="xsd:string" gw:type="java.lang.String"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>

联系LM.xsd

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:gw="http://w.com/xsd"
xmlns="http://w.com/location.contactlm"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
targetNamespace="http://w.com/location.contactlm"
elementFormDefault="qualified" jaxb:version="2.1">
<xsd:annotation>
<xsd:appinfo>
<!-- <jaxb:schemaBindings> -->
<!-- <jaxb:package name="location.contactm"/> -->
<!-- </jaxb:schemaBindings> -->
</xsd:appinfo>
</xsd:annotation>

<xsd:element name="Contact" type="Contact" nillable="true"/>

<xsd:complexType name="Contact">
<xsd:sequence>
<xsd:element name="RefID" type="xsd:string" nillable="true"
minOccurs="0" gw:type="java.lang.String"/>
</xsd:sequence>
</xsd:complexType>


</xsd:schema>

最后是绑定(bind)文件:

绑定(bind).xjb

<jaxb:bindings
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:gw="http://w.com/xsd"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
xmlns="http://w.com/location.contactlm"

targetNamespace="http://w.com/location.contactlm"
jaxb:version="2.1">

<jaxb:bindings schemaLocation="ContactM.xsd">
<jaxb:bindings node=".//xs:element[@name='Contact']">
<jaxb:class name="ContactM"/>
</jaxb:bindings>
<jaxb:schemaBindings>
<jaxb:package name="location.contactm" />
</jaxb:schemaBindings>
</jaxb:bindings>

<jaxb:bindings schemaLocation="ContactLM.xsd">
<jaxb:bindings node=".//xs:element[@name='Contact']">
<jaxb:class name="ContactCLM"/>
</jaxb:bindings>
<jaxb:schemaBindings>
<jaxb:package name="location.contactlm" />
</jaxb:schemaBindings>
</jaxb:bindings>

</jaxb:bindings>

为了完整起见,这是我的命令及其输出

D:\stackoverflow\sample>xjc ContactM.xsd -b bind.xjb
parsing a schema...
compiling a schema...
location\contactm\Contact.java
location\contactm\ContactM.java
location\contactm\ObjectFactory.java
location\contactm\package-info.java
location\contactlm\Contact.java
location\contactlm\ContactCLM.java
location\contactlm\ObjectFactory.java
location\contactlm\package-info.java

希望这有帮助。

关于java - XJB [错误] 为目标命名空间定义了多个 <schemaBindings>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18223119/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com