gpt4 book ai didi

xml - XJC错误提示 “chameleon schema”

转载 作者:行者123 更新时间:2023-12-02 10:42:14 24 4
gpt4 key购买 nike

我在对架构运行XJC时遇到问题。我从架构中删除了几乎所有的定义,只剩下了最少的重现问题。当我针对此最小架构运行XJC时:

 1 <?xml version="1.0" encoding="utf-8"?>
2 <xs:schema id="Catalog" xmlns:xs="http://www.w3.org/2001/XMLSchema" >
3
4 <xs:element name="Attribute">
5 <xs:complexType>
6 <xs:simpleContent>
7 <xs:extension base="xs:string">
8 <xs:attribute name="type" type="xs:string" />
9 </xs:extension>
10 </xs:simpleContent>
11 </xs:complexType>
12 </xs:element>
13
14 <xs:element name="SampleSet" substitutionGroup="Attribute"/>
15 </xs:schema>

我收到以下XJC错误:
C:\Users\mbmas_000\workspace\JMish>del src\jmish\jaxb\*.java

C:\Users\mbmas_000\workspace\JMish>xjc -d src -p jmish.jaxb JMish.xsd
parsing a schema...
compiling a schema...
[ERROR] A class/interface with the same name "jmish.jaxb.Attribute" is already in use. Use a class customization to resolve this conflict.
line 5 of file:/C:/Users/mbmas_000/workspace/JMish/JMish.xsd

[ERROR] (Relevant to above error) another "Attribute" is generated from here.
line 5 of file:/C:/Users/mbmas_000/workspace/JMish/JMish.xsd

[ERROR] (Relevant to above error) This confusing error happened most likely because the schema uses a technique called "chameleon schema", which causes a single definition to be loaded multiple times into different namespaces. See http://forums.java.net/jive/thread.jspa?threadID=18631 for more about this.
line 5 of file:/C:/Users/mbmas_000/workspace/JMish/JMish.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
line 5 of file:/C:/Users/mbmas_000/workspace/JMish/JMish.xsd

[ERROR] (Related to above error) This is the other declaration.
line 5 of file:/C:/Users/mbmas_000/workspace/JMish/JMish.xsd

Failed to produce code.

C:\Users\mbmas_000\workspace\JMish>pause
Press any key to continue . . .

但是....如果我将 SampleSet的名称更改为其他名称,例如 xSampleSet,则XJC会正确完成。我正在使用JDK 1.7.0_45的XJC版本2.2.4-2。

难道我做错了什么? SampleSet是某种保留的元素名称吗?

最佳答案

不,这不是变色龙架构问题。

我认为发生这种情况是因为Attribute元素及其匿名内部复杂类型都获得了自己的类。两者都命名为Attribute

尝试自定义复杂类型以使用其他名称:

<jaxb:bindings schemaLocation="..." node="/xs:schema">
<jaxb:bindings node="xs:element[@name='Attribute']/xs:complexType">
<jaxb:class name="AttributeType"/>
</jaxb:bindings>
</jaxb:bindings>

(草图,未经测试。)

或使用 nameXmlTransform

我不认为这是一个错误。

关于xml - XJC错误提示 “chameleon schema”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25457713/

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