解决随附的XSD的JAXB编译中的命名冲突 [英] Resolve naming conflict in included XSDs for JAXB compilation

查看:76
本文介绍了解决随附的XSD的JAXB编译中的命名冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am currently trying to compile with JAXB (IBM build 2.1.3) a pair of schema files into the same package. Each will compile on it's own, but when trying to compile them together i get a element naming conflict due to includes. My question is; is there a way to specify with an external binding a resolution to the naming collision.

示例文件如下.在该示例中,有问题的元素称为通用",在incA和incB中都定义了:

Example files follow. In the example the offending element is called "Common", which is defined in both incA and 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的一次调用中编译时出现的编译器错误:

Compiler error when both are compiled from one evocation of xjb:


[ERROR] 'Common' is already defined
 line 9 of file:/C:/temp/incB.xsd
[ERROR] (related to above error) the first definition appears here
 line 9 of file:/C:/temp/incA.xsd

(仅供参考,这是解决与编译OAGIS8 SP3软件包有关的问题的概括)

(For reference, this is a generalization to resolve an issue with compiling the OAGIS8 SP3 package)

推荐答案

我已经确定,尽管进一步的研究表明,由于名称空间冲突,试图一次编译所有这些片段是不可能的.我决定进行的工作是将每组模式子集编译到各自的程序包中,并在尝试解组XML之前对传入的XML进行启发式测试.

I have determined though further research that trying to compile all these fragments at once is impossible, due to the name-space collision. The work around I decided upon was to compile each set of schema subsets into their own packages, and perform a heuristic test on the incoming XML before attempting to unmarshal it.

这篇关于解决随附的XSD的JAXB编译中的命名冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆