问题:如何使 xjc/Jaxb 为同一命名空间中包含重复元素定义的多个模式生成正确的 java 类?
信息:我有三个 .xsd 模式:A、B 和 C。它们都具有相同的目标命名空间。
它们都是给我的 3 个 shemas,我无论如何都不允许以任何方式改变它们。
它们 A 有一些在 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>
当使用 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
同样的情况也发生在其他元素上:arcgYearType、arcgYearMonthType 和 arcDateType。
我读过有关绑定文件的内容,也许可以解决这个问题,但我不确定如何做到这一点,因此示例将是高度首选。
根据您的描述,我认为 XSD 文件之间不存在包含关系。另外,我必须假设您正在尝试重用内容重叠的类。
简单的方法是独立“编译”每个文件,并为每个 XSD 文件提供不同的 Java 包。这里的问题是,如果您尝试将内容从一个 XML 链接到另一个 XML(即从 A 解组,然后编组到 B),则类 C1 位于包 com.A 中,类 C1 位于包 com.B 中,而匹配相同的 XSD 复杂类型,不可“互换”;你必须在它们之间进行转换。您需要自定义绑定文件,或者如果您使用 NetBeans,只需在 JAXB 向导中设置不同的包即可。
最好的方法可能是使用剧集(请参阅这对SO https://stackoverflow.com/questions/5869547/jaxb-creating-modules-for-reuse)。处理 A.xsd,然后使用该情节处理 B.xsd 等。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)