Resolve name conflict in included XSD to compile JAXB

I'm currently trying to compile with JAXB (IBM build 2.1.3) a couple of schema files into the same package. Each of them will compile independently, but when I try to compile them together, I get a conflict of element names due to inclusions. My question is: is there a way to specify name resolution resolution with external binding.

The following are sample files. In this 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 compiled from the same xjb call:

 [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 solve the problem with compiling the OAGIS8 SP3 package)

+2
java jaxb xjc
source share
1 answer

I determined that further research that trying to collect all of these fragments at once is impossible, due to a collision of the namespace. The work I decided on was to compile each set of subsets of the schema into their own packages and perform a heuristic test on the incoming XML before trying to undo it.

+2
source share

All Articles