JAXB workaround for importing Chameleon XSD?

This is my first question, so please be careful;)

I am stuck with a strange problem. Essentially, I get three XSD definitions, for example:

PartA.xsd targetNameSpace="PartA" include="PartB.xsd" PartB.xsd <!-- no namespace definition!!! --> PartC.xsd targetNameSpace="PartC" inlude="PartB.xsd" import="PartA.xsd" 

Error popping up when binding PartC through JAXB classes to Java:

  • A class / interface with the same name "b.exampleType" is already in use. Use class customization to resolve this conflict.
  • This confusing error occurred most likely because the scheme uses a technique called the "chameleon scheme", which forces one definition to load several times into different namespaces. See http://forums.java.net/jive/thread.jspa?threadID=18631 for details.

Following the link, I found out that the actual error lies in PartB, which does not have a namespace declaration! This method is called Chameleon Schema . Certain types in PartB will use the importing XSD namespace.

So, in my case, there are two namespaces for the same type:

  • "Desk"
  • "PARTC"

And this is where JAXB breaks down. I did not find a way to properly bind PartC. And (to make things complicated) I have a chance to change the original XSD definitions!

Has anyone come across this phenomenon or something like that and has a valid workaround?

+7
java xml xsd jaxb
source share
3 answers

I ran into the same problem using wsdl2java :

Error WSDLToJava: JAXB thrown: a class / interface with the same name "Respuesta" is already in use. Use class customization to resolve this conflict.

But this question pointed me in the right direction. Using wsdl2java from CFX, you can customize how elements are bound to classes using the binding.xml file. For example:

 /Applications/apache-cxf-2.7.13/bin/wsdl2java -b ./src/main/resources/binding.xml -V -d src/main/java -compile -classdir target/classes http://someurl.wsdl 

The key is to explain in the binding.xml file the name of a specific xsd element with one specific class name in order to avoid failures:

 <jxb:bindings xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" version="2.1"> <jxb:bindings schemaLocation="./someXsdFile.xsd"> <!-- Rename the respuesta class to resolve a naming conflict with other Respuesta element already defined--> <jxb:bindings node="//xs:element[@name='respuesta']/xs:complexType"> <jxb:class name="Respuesta2" /> </jxb:bindings> </jxb:bindings> </jxb:bindings> 

Hope this helps the next person with this problem using wsdl2java. I believe that other tools should allow similar approbations to this problem.

+3
source share

The following is available, although it does not contain many details:

+1
source share

I had the same problem and a google search engine landed on me. Your question is quite detailed, and I was able to find the answer, what I did is put the namespace in PartB.xsd and use XJC to generate java classes. I added the following:

xmlns: ns = "http://www.myCompany.com/2009/01/CustSchema" targetNamespace = "http://www.myCompany.com/2009/01/CustSchema"

0
source share

All Articles