JAXB XJC - 将XML模式版本绑定到类名

时间:2012-09-11 17:35:02

标签: jaxb xjc xml-binding

我们有两个XML模式,它们具有相同的元素名称但名称空间不同。当我使用xjc时,编译器将元素分配给相同的类路径和元素。如下所示,根问题在于使用前导数字处理XML Schema名称空间;特别是1.0和1.1。 XJC正在将这些差异URI编译为同一个类路径;特别是_1。这导致与同一类路径发生冲突:

com.companyabc.namespaces.eda.process._1.TheChangeType

bindings.xjb中将1.0绑定到_1_0和1.1绑定到_1_1的语法是什么?

感谢!!!

XML架构1:http://namespaces.companyABC.com/EDA/Process/1.0/TheChange

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:p10="http://namespaces.companyABC.com/EDA/Process/1.0"
targetNamespace="http://namespaces.companyABC.com/EDA/Process/1.0"
elementFormDefault="qualified">
<xs:element name="TheChange" type="p10:TheChangeType" />
<xs:complexType name="TheChangeType">
    <xs:sequence>
        <xs:element name="Field1" type="xs:string" />
    </xs:sequence>
</xs:complexType>
</xs:schema>

XML架构2:http://namespaces.companyABC.com/EDA/Process/1.1/TheChange

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:p11="http://namespaces.companyABC.com/EDA/Process/1.1"
targetNamespace="http://namespaces.companyABC.com/EDA/Process/1.1"
elementFormDefault="qualified">
<xs:element name="TheChange" type="p11:TheChangeType" />
<xs:complexType name="TheChangeType">
    <xs:sequence>
        <xs:element name="Field1" type="xs:string" />
        <xs:element name="Field2" type="xs:string" />
    </xs:sequence>
</xs:complexType>
</xs:schema>

错误:

[ant:xjc] [ERROR] A class/interface with the same name "com.companyabc.namespaces.eda.process._1.TheChangeType" is already in use. Use a class customization to resolve this conflict.
[ant:xjc]   line 3 of file:/D:/source/1.0/TheChange.xsd

这是使用XSD架构注释的解决方案。然而,解决方案应该作为bindings.xjb与注释中的绑定模式实现。注释将要求对每个模式进行注释,这是一个问题。

<xsd:annotation>
    <xsd:appinfo>
        <jaxb:schemaBindings>
            <jaxb:package name="com.companyabc.namespaces.eda.process._1_0" />
        </jaxb:schemaBindings>
    </xsd:appinfo>
</xsd:annotation>

            <jaxb:package name="com.companyabc.namespaces.eda.process._1_1" />

如何在bindings.xjb中将此注释实现为绑定模式?

0 个答案:

没有答案