xml - XJC 错误提示 "chameleon schema"

标签 xml compiler-errors xsd xjc

我在针对我的架构运行 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/

相关文章:

sql-server - 如何从 XSD 架构构建数据库并导入 XML 数据

xml - 即时动态构建 JavaFX UI

java - 如何处理Java编码问题(尤其是xml)?

java - JAXB 如何编码可选或可为空的元素

generics - 如何在rust宏中扩展多个特征范围?

android - 我该如何解决这个错误并转换类型?

java - jaxb:意外元素(uri :"",本地 :"head")- 没有 "head"元素

java - Spring Framework XML 配置元数据和命名空间

android - CardView 内的圆角底部 TextView

java - 如何在Eclipse中自定义并触发Java编译错误