Ale*_*der 29 java schema jaxb xjc
我有两个使用JAXB处理的模式.第一个模式已预处理,并使用剧集文件(http://www.java.net/blog/2006/09/05/separate-compilation-jaxb-ri-21)使用此信息.第二个模式导入第一个模式,并再次使用jaxb进行处理.这一切都按预期工作.
但是现在我在第一个模式中有一个元素,在第二个模式中使用了一个引用.
架构a:
<schema elementFormDefault="qualified" xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:test="http://www.example.org/Test/"
targetNamespace="http://www.example.org/Test/">
<element name="type" type="test:MyType"></element>
Run Code Online (Sandbox Code Playgroud)
架构b:
<schema elementFormDefault="qualified"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:second="http://www.example.org/Second/"
xmlns:test="http://www.example.org/Test/"
targetNamespace="http://www.example.org/Second/">
<import namespace="http://www.example.org/Test/" />
<complexType name="SomeType">
<sequence>
<element ref="test:type" minOccurs="1" maxOccurs="unbounded" />
</sequence>
</complexType>
Run Code Online (Sandbox Code Playgroud)
在处理过程中没有任何错误,但两个模式的生成代码提供了相同的方法:
public JAXBElement<EventType> createType(TypeType value)
Run Code Online (Sandbox Code Playgroud)
在运行时,这会导致以下错误:
com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of
IllegalAnnotationExceptions
The element name {http://www.example.org/Type/}type has more than one mapping.
Run Code Online (Sandbox Code Playgroud)
如何防止JAXB创建重复的createType方法?
提前致谢!
更新:我在JAXB邮件列表上询问了同样的问题,在该列表中我还发布了一个工作示例.可以在以下位置找到该主题和示例:http://java.net/projects/jaxb/lists/users/archive/2011-03/message/18
在这个列表中,我被建议了一个解决方法,现在我可以按照我喜欢的方式使用模式.但我仍然认为JAXB不应该创建额外的"创建"方法,因为它应该已经在剧集文件中.
我当时写了一些架构定义。您在第二个架构声明中声明您的第一个 xsd,然后导入它。
根据 MSDN,当您导入 XSD 时,您不会将其包含在架构声明中。这是它在模式声明中的位置。
xmlns:test="http://www.example.org/Test/"
删除它并执行导入... ( <xs:import namespace="http://www.example.com/IPO" /> )
请参阅:http ://msdn.microsoft.com/en-us/library/ms256480.aspx
| 归档时间: |
|
| 查看次数: |
6589 次 |
| 最近记录: |