使用JAXB编译包含相同元素的重复定义的多个XSD [英] Compile several XSD's containing duplicate definitions of the same element with JAXB

查看:465
本文介绍了使用JAXB编译包含相同元素的重复定义的多个XSD的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:
如何让xjc / Jaxb为同一名称空间中包含重复元素定义的多个模式生成propper javaclasses?

Question: How do i make xjc/Jaxb generate the propper javaclasses for several schemas containing duplicate elementdefinitions in the same namespace?

信息:
我有三个.xsd架构:A,B和C.所有都有相同的targetnamespace。
他们都是给我的3个shemas,我不会以任何方式允许以任何方式改变它们。

Information: I have three .xsd schemas: A,B and C. All have the same targetnamespace. They are all 3 shemas that has been given to me, and i am not, in any way possible, allowed to change them in any way.

他们A有一些元素也可以在B或C中找到(但A也有很多自我声明的元素)
示例:这与A和C的代码相同:

They A has some elements that is also found in B or C (but A has a lot of self declared elements as well) Example: This is the same "code" for A and C:

<xs:simpleType name="y_ym_ymdDatoType">
    <xs:union memberTypes="arcgYearType arcgYearMonthType arcDateType"/>
</xs:simpleType>
<xs:simpleType name="arcgYearType">
    <xs:restriction base="xs:gYear">
        <xs:minInclusive value="1700"/>
        <xs:maxInclusive value="2100"/>
    </xs:restriction>
</xs:simpleType>
<xs:simpleType name="arcgYearMonthType">
    <xs:restriction base="xs:gYearMonth">
        <xs:minInclusive value="1700-01"/>
        <xs:maxInclusive value="2100-12"/>
    </xs:restriction>
</xs:simpleType>
<xs:simpleType name="arcDateType">
    <xs:restriction base="xs:date">
        <xs:minInclusive value="1700-01-01"/>
        <xs:maxInclusive value="2100-12-31"/>
    </xs:restriction>
</xs:simpleType>

当使用xjc将它们编译成javaclasses时,我得到以下异常:

When using xjc to compile them into javaclasses, i get the following exception:

[ERROR] 'y_ym_ymdDatoType' is already defined
 line 297 of file:../c.xsd

[ERROR] (related to above error) the first definition appears here
 line 309 of file:../a.xsd

并且其他元素也是如此:arcgYearType,arcgYearMonthType和arcDateType。

and the same happens to the other elements: arcgYearType, arcgYearMonthType and arcDateType.

我读过一篇可能解决这个问题的绑定文件问题,但我不知道怎么做,所以示例将是首选。

I have read about a binding file that maybe could solve this problem, but i am not sure on how to do it so examples will be highly preferred.

推荐答案

您可以使用手动解决冲突绑定文件。下面是一个示例,您可以在其中为冲突名称指定自定义名称:

You can resolve conflicts manually using binding file. Here is the example, where you can specify your custom name for conflicting names:

<bindings schemaLocation="../party.xsd" version="1.0" node="/xs:schema">
    <bindings node="//xs:complexType[@name='FixedIncomeBook']">
        <class name="PartyFixedIncomeBook"/>
    </bindings>
</bindings>

这篇关于使用JAXB编译包含相同元素的重复定义的多个XSD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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