使用JAXB编译包含相同元素的重复定义的多个XSD

Sof*_*sen 8 java xsd jaxb xjc

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

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

它们有一些也可以在B或C中找到的元素(但是A也有很多自我声明的元素)例子:这是A和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>
Run Code Online (Sandbox Code Playgroud)

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

[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
Run Code Online (Sandbox Code Playgroud)

其他元素也是如此:arcgYearType,arcgYearMonthType和arcDateType.

我已经阅读了一个可能解决这个问题的绑定文件,但我不知道如何做到这一点,所以示例将是首选.

Ser*_*nov 1

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

<bindings schemaLocation="../party.xsd" version="1.0" node="/xs:schema">
    <bindings node="//xs:complexType[@name='FixedIncomeBook']">
        <class name="PartyFixedIncomeBook"/>
    </bindings>
</bindings>
Run Code Online (Sandbox Code Playgroud)