带有元素引用的JAXB多个模式 [英] JAXB multiple schemas with element reference

查看:72
本文介绍了带有元素引用的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/library/ms256480.aspx

这篇关于带有元素引用的JAXB多个模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆