带有元素引用的 JAXB 多个模式
我有两个使用 JAXB 处理的模式.第一个模式经过预处理,并使用剧集文件使用此信息(遵循 http://www.java.net/blog/2006/09/05/separate-compilation-jaxb-ri-21).第二个模式导入第一个,并再次使用 jaxb 进行处理.这一切都按预期工作.
I have two schemas which are processed using JAXB. The first schema is preprocessed and information of this is used using an episode file (following http://www.java.net/blog/2006/09/05/separate-compilation-jaxb-ri-21). The second schema imports the first, and again using jaxb, is processed. This all works as expected.
但现在我在第一个模式中有一个元素,在第二个模式中使用引用.
But now I have an element in the first schema, which is used in the second using a reference.
架构 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>
架构 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>
在处理过程中没有任何问题,但是为两种模式生成的代码提供了相同的方法:
During processing nothing is wrong, but the generated code for both schemas provide the same method:
public JAXBElement<EventType> createType(TypeType value)
在运行时,这会导致以下错误:
At runtime, this results in the following error:
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.
如何防止 JAXB 创建重复的 createType 方法?
How can I prevent JAXB from creating the duplicate createType methods?
提前致谢!
更新:我在 JAXB 邮件列表上提出了同样的问题,在该列表上我还发布了一个工作示例.可以在以下位置找到线程和示例:http://java.net/projects/jaxb/lists/users/archive/2011-03/message/18
Update: I asked this same question on the JAXB mailing list, on that list I also posted a working example. The thread and example can be found at: http://java.net/projects/jaxb/lists/users/archive/2011-03/message/18
在此列表中,有人向我建议了一种解决方法,现在我可以按照自己喜欢的方式使用架构.但我仍然认为 JAXB 不应该创建额外的创建"方法,因为它应该已经在剧集文件中.
On this list I've been suggested a workaround, and now I can use the schemas the way I like. But I still think JAXB should not create the additional "create" method, since it should already be in the episode file.
推荐答案
我已经写了一些架构定义.您在第二个架构声明中声明了您的第一个 xsd,然后您正在导入它.
I've written a few Schema Definitions in my day. You are declaring your first xsd in your second schema declaration and then you are importing it.
根据 MSDN,当您导入 XSD 时,您不会将其包含在架构声明中.这是它在您的架构声明中的位置.
As per MSDN, when you import an XSD you do not include it in the Schema Declaration. This is where it is in your schema declaration.
xmlns:test="http://www.example.org/Test/"
xmlns:test="http://www.example.org/Test/"
删除它并进行导入... ( <xs:import namespace="http://www.example.com/IPO"/>
)
Remove this and just do the import... ( <xs:import namespace="http://www.example.com/IPO" />
)
请参阅:http://msdn.microsoft.com/en-us/库/ms256480.aspx
相关文章