2

我目前正在尝试使用 JAXB (IBM build 2.1.3) 将一对模式文件编译到同一个包中。每个都将自行编译,但是当尝试将它们编译在一起时,由于包含,我会遇到元素命名冲突。我的问题是;有没有办法通过外部绑定指定命名冲突的解决方案。

示例文件如下。在示例中,违规元素称为“Common”,它在 incA 和 incB 中都定义:

incA.xsd

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" 
    targetNamespace="http://www.example.org/"
    xmlns:tns="http://www.example.org/" elementFormDefault="qualified">
    <complexType name="TypeA">
        <sequence>
            <element name="ElementA" type="string"></element>
        </sequence>
    </complexType>
    <!-- Conflicting element -->
    <element name="Common" type="tns:TypeA"></element>
</schema>

incB.xsd

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" 
    targetNamespace="http://www.example.org/"
    xmlns:tns="http://www.example.org/" elementFormDefault="qualified">
    <complexType name="TypeB">
        <sequence>
            <element name="ElementB" type="int"></element>
        </sequence>
    </complexType>
    <!-- Conflicting element -->
    <element name="Common" type="tns:TypeB"></element>
</schema>

a.xsd

<?xml version="1.0" encoding="UTF-8"?>
<schema targetNamespace="http://www.example.org/"
    elementFormDefault="qualified" xmlns="http://www.w3.org/2001/XMLSchema"
    xmlns:tns="http://www.example.org/">
    <include schemaLocation="incA.xsd"></include>
    <complexType name="A">
        <sequence>
            <element ref="tns:Common"></element>
        </sequence>
    </complexType>
</schema>

B.xsd

<?xml version="1.0" encoding="UTF-8"?>
<schema targetNamespace="http://www.example.org/"
    elementFormDefault="qualified" xmlns="http://www.w3.org/2001/XMLSchema"
    xmlns:tns="http://www.example.org/">
    <include schemaLocation="incB.xsd"></include>
    <complexType name="B">
        <sequence>
            <element ref="tns:Common"></element>
        </sequence>
    </complexType>
</schema>

从 xjb 的一次调用编译两者时的编译器错误:

[错误] 'Common' 已经定义
 文件第 9 行:/C:/temp/incB.xsd
[ERROR](与上述错误有关)第一个定义出现在这里
 文件第 9 行:/C:/temp/incA.xsd

(作为参考,这是解决编译 OAGIS8 SP3 包的问题的概括)

4

1 回答 1

2

我已经确定,由于名称空间冲突,尝试一次编译所有这些片段是不可能的。我决定的解决方法是将每组模式子集编译到它们自己的包中,并在尝试解组之前对传入的 XML 执行启发式测试。

于 2010-05-05T16:19:17.657 回答