gpt4 book ai didi

java - xjc 错误 : "Two declarations cause a collision" on valid . xsd

转载 作者:行者123 更新时间:2023-11-30 08:17:17 25 4
gpt4 key购买 nike

我有一个有效的 .xsd 作为 API 描述。这是(没有冗余代码):

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:simpleType name="String">
<xsd:restriction base="xsd:string"/>
</xsd:simpleType>

<xsd:complexType name="ErrorType">
<xsd:sequence>
<xsd:element name="Type">
<xsd:complexType>
<xsd:attribute name="Name" type="String" use="required"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name="ErrorTypeType">
<xsd:attribute name="Code" type="String" use="required"/>
<xsd:attribute name="Name" type="String" use="required"/>
</xsd:complexType>
</xsd:schema>

它由 http://www.validome.org/grammar/validate/ 验证

但是 xjc MySchema.xsd 引发了以下错误:

parsing a schema...
compiling a schema...
[ERROR] Two declarations cause a collision in the ObjectFactory class.
line 17 of file:/C:/Users/dev05/Downloads/MySchema.xsd

[ERROR] (Related to above error) This is the other declaration.
line 10 of file:/C:/Users/dev05/Downloads/MySchema.xsd

Failed to produce code.

我应该要求 API 创建者更改它(这很难)还是有一些解决方法来解决这个问题?

最佳答案

解决我添加绑定(bind)文件的问题:

bindings.xml

<jaxb:bindings 
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
jaxb:extensionBindingPrefixes="xjc"
version="2.1">
<jaxb:globalBindings generateIsSetMethod="true" fixedAttributeAsConstantProperty="true">
<xjc:serializable />
</jaxb:globalBindings>
<jaxb:bindings schemaLocation="Common.xsd">
<jaxb:bindings node="//xs:complexType[@name='ErrorTypeType']">
<jaxb:class name="ErrorTypeType1"/>
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>

shell 命令将是:

xjc -b bindings.xml -extension MySchema.xsd 

关于java - xjc 错误 : "Two declarations cause a collision" on valid . xsd,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27939612/

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