Resolve naming conflict in included XSDs for JAXB compilation
Posted
by Jason Faust
on Stack Overflow
See other posts from Stack Overflow
or by Jason Faust
Published on 2010-04-26T15:16:10Z
Indexed on
2010/04/26
21:03 UTC
Read the original article
Hit count: 306
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/">
<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>
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)
© Stack Overflow or respective owner