请帮忙:xjc 抛出“两个声明导致 ObjectFactory 类中发生冲突”
采用以下简化的 XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="com.acme" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Widget">
<xs:complexType>
<xs:sequence>
<xs:element
minOccurs="0" name="color" nillable="true" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="WidgetColor" type="xs:string" />
</xs:schema>
然后,尝试以下操作:
xjc test.xsd
您应该总是得到以下异常:
parsing a schema...
compiling a schema...
[ERROR] Two declarations cause a collision in the ObjectFactory class.
line 11 of file:/C:/test.xsd
[ERROR] (Related to above error) This is the other declaration.
line 7 of file:/C:/test.xsd
Failed to produce code.
请注意,有一个元素名称“Widget”,它是一个复杂类型,并且具有名为“”的元素颜色”。在与元素“Widget”同一级别上,还有一个名为“WidgetColor”的简单元素。
更令人费解的是,如果您删除属性 minOccurs="0" OR,您删除属性 nillable如果“color”元素序列为“true”,则 xjc 成功编译架构。
有没有人见过这个问题或者可以提出解决方案?
谢谢,
迈克。
Take the following over simplified XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="com.acme" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Widget">
<xs:complexType>
<xs:sequence>
<xs:element
minOccurs="0" name="color" nillable="true" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="WidgetColor" type="xs:string" />
</xs:schema>
Then, attempt the following:
xjc test.xsd
You should invariably get the following exception:
parsing a schema...
compiling a schema...
[ERROR] Two declarations cause a collision in the ObjectFactory class.
line 11 of file:/C:/test.xsd
[ERROR] (Related to above error) This is the other declaration.
line 7 of file:/C:/test.xsd
Failed to produce code.
Notice that There is an element name "Widget" which is a complexType and has elements named "color". There is also, at the same level as the element "Widget", an simple element named "WidgetColor".
What is more puzzling is that if you remove the attribute minOccurs="0" OR you remove the attribute nillable="true" from the "color" element sequence, xjc compiles the schema successfully.
Has anyone ever seen this problem or can suggest a solution?
Thanks,
Mike.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我终于想出了如何解决我的问题。它在于使用自定义绑定为声明之一指定不同的类名称。
custom-binding.xjb 的内容
操作:
Patience et longueur de temps valent mieux que rage et acharnement...!
Well I finally figured out how to fix my problem. It lies in using a custom binding to specify a distinct class name for one of the declarations.
Content of custom-binding.xjb
Operation:
Patience et longueur de temps valent mieux que rage et acharnement...!