tags:

views:

310

answers:

1

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.

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/"&gt;
    <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/"&gt;
    <include schemaLocation="incB.xsd"></include>
    <complexType name="B">
        <sequence>
            <element ref="tns:Common"></element>
        </sequence>
    </complexType>
</schema>

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

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

A: 

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.

Jason Faust