我目前正在尝试使用 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 包的问题的概括)