我遇到了针对我的架构运行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
是某种保留的元素名称吗?
答案 0 :(得分:2)
不,这不是变色龙模式问题。
我认为这种情况正在发生,因为元素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
。
我认为这不是一个错误。