首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >XJC错误提示“变色龙模式”

XJC错误提示“变色龙模式”
EN

Stack Overflow用户
提问于 2014-08-23 09:49:23
回答 1查看 820关注 0票数 2

我在对我的模式运行XJC时遇到问题。我已经从模式中删除了几乎所有的定义,只留下最少的定义来重现问题。当我对这个最小模式运行XJC时:

代码语言:javascript
复制
 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错误:

代码语言:javascript
复制
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是某种保留的元素名吗?

EN

回答 1

Stack Overflow用户

发布于 2014-10-17 14:30:04

不,这不是变色龙模式问题。

我认为这是因为元素Attribute和它的匿名内部复杂类型都有自己的类。这两个名称都是Attribute

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

代码语言:javascript
复制
<jaxb:bindings schemaLocation="..." node="/xs:schema">
  <jaxb:bindings node="xs:element[@name='Attribute']/xs:complexType">
    <jaxb:class name="AttributeType"/>
  </jaxb:bindings>
</jaxb:bindings>

(粗略草图,未经测试。)

或者使用nameXmlTransform

我不认为这是一个bug。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25457713

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档