"root element collision" while trying use commonality in two XML schemas

L

lbrtchx

Hi *,

I basically have two xml schemas which only differ in one attribute, so I
built both around their commonality.

// __ NQItm00.xsd
<?xml version="1.0" encoding="UTF-8"?>

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:include schemaLocation="commons00.xsd"/>
<xsd:element name="NQx">
<xsd:complexType>
<xsd:sequence minOccurs="0" maxOccurs="250">
<xsd:element ref="NQItm" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>

// __
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:include schemaLocation="commons00.xsd"/>
<xsd:element name="Qx">
<xsd:complexType>
<xsd:sequence minOccurs="0" maxOccurs="250">
<xsd:element ref="QItm" />
</xsd:sequence>

</xsd:complexType>
</xsd:element>
</xsd:schema>

// __ with commons00.xsd as:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<xsd:element name="A">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="APfx" type="xsd:string" />
<xsd:element name="ASfx" type="xsd:string" />
</xsd:sequence>
<xsd:attribute name="AId" type="xsd:nonNegativeInteger" use="required" />
<xsd:attribute name="ALUpDiff" type="xsd:nonNegativeInteger"
use="required" />
<xsd:attribute name="AUps" type="xsd:nonNegativeInteger"
use="required" />
</xsd:complexType>
</xsd:element>

<xsd:element name="QAns">
<xsd:complexType>
<xsd:sequence minOccurs="1" maxOccurs="32">
<xsd:element ref="A" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>

<xsd:element name="THead">
<xsd:complexType>
<xsd:attribute name="ixTH" type="xsd:nonNegativeInteger"
use="required" />
<xsd:attribute name="THId" type="xsd:nonNegativeInteger"
use="required" />
<xsd:attribute name="ColName" type="xsd:string" use="required" />
<xsd:attribute name="Fx" type="xsd:double" use="optional" />
</xsd:complexType>
</xsd:element>

<xsd:element name="THeaders">
<xsd:complexType>
<xsd:sequence minOccurs="1" maxOccurs="12">
<xsd:element ref="THead" />
</xsd:sequence>
<xsd:attribute name="ixHTMLFT" type="xsd:nonNegativeInteger"
use="required" />
</xsd:complexType>
</xsd:element>

<xsd:element name="Ap">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="QAns" />
<xsd:element ref="THeaders" />
</xsd:sequence>
<xsd:attribute name="ix" type="xsd:nonNegativeInteger" use="required" />
</xsd:complexType>
</xsd:element>

<xsd:element name="Aprx">
<xsd:complexType>
<xsd:sequence minOccurs="1" maxOccurs="5">
<xsd:element ref="Ap" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>

<xsd:complexType name="QTp">
<xsd:sequence>
<xsd:element name="QI" type="xsd:string" />
<xsd:element name="QC" type="xsd:string" />
<xsd:element name="Q" type="xsd:string" />
<xsd:element name="QN" type="xsd:string" />
<xsd:element name="ixTpk" type="xsd:nonNegativeInteger" />
<xsd:element name="ixQAnsTp" type="xsd:nonNegativeInteger" />
<xsd:element name="ixQAnsVal" type="xsd:nonNegativeInteger" />
<xsd:element ref="Aprx" />
</xsd:sequence>
<xsd:attribute name="QId" type="xsd:nonNegativeInteger" use="required" />
<xsd:attribute name="QLUpDiff" type="xsd:nonNegativeInteger"
use="required" />
<xsd:attribute name="QUps" type="xsd:nonNegativeInteger" use="required" />
</xsd:complexType>

<xsd:element name="QItm" type="QTp" />

<!-- done the monkey way "QTp" may de extendable -->

<xsd:complexType name="NQTp">
<xsd:sequence>
<xsd:element name="QI" type="xsd:string" />
<xsd:element name="QC" type="xsd:string" />
<xsd:element name="Q" type="xsd:string" />
<xsd:element name="QN" type="xsd:string" />
<xsd:element name="ixTpk" type="xsd:nonNegativeInteger" />
<xsd:element name="ixQAnsTp" type="xsd:nonNegativeInteger" />
<xsd:element name="ixQAnsVal" type="xsd:nonNegativeInteger" />
<xsd:element ref="Aprx" />
</xsd:sequence>
<xsd:attribute name="QId" type="xsd:nonNegativeInteger" use="required" />
<xsd:attribute name="QLUpDiff" type="xsd:nonNegativeInteger"
use="required" />
<xsd:attribute name="QUps" type="xsd:nonNegativeInteger" use="required" />
<xsd:attribute name="cTm" type="xsd:nonNegativeInteger" use="required" />
</xsd:complexType>
<xsd:element name="NQItm" type="NQTp" />
</xsd:schema>

// __
Everything parses fine independently but when yo try to load both schemas
you get:

// - - - - - - - - - - - - - - - - - - - - - -
javax.xml.bind.JAXBException: root element collision detected for {}Aprx -
unable to create JAXBContext with the given contextPath
at
jaxb.NQItm00.impl.runtime.GrammarInfoFacade.detectRootElementCollisions(GrammarInfoFacade.java:114)
at
jaxb.NQItm00.impl.runtime.GrammarInfoFacade.<init>(GrammarInfoFacade.java:35)
at
jaxb.NQItm00.impl.runtime.GrammarInfoFacade.createGrammarInfoFacade(GrammarInfoFacade.java:185)
at
jaxb.NQItm00.impl.runtime.DefaultJAXBContextImpl.<init>(DefaultJAXBContextImpl.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
at
com.sun.xml.bind.ContextFactory_1_0_1.createContext(ContextFactory_1_0_1.java:50)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:96)
at javax.xml.bind.ContextFinder.searchcontextPath(ContextFinder.java:229)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:149)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:281)
at JAXB06.setCtxt(JAXB06.java:106)
at TestJAXB06.main(TestJAXB06.java:9)
--------------- linked to ------------------
javax.xml.bind.JAXBException
- with linked exception:
[javax.xml.bind.JAXBException: root element collision detected for {}Aprx -
unable to create JAXBContext with the given contextPath]
at
com.sun.xml.bind.ContextFactory_1_0_1.createContext(ContextFactory_1_0_1.java:56)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:96)
at javax.xml.bind.ContextFinder.searchcontextPath(ContextFinder.java:229)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:149)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Why is this happening? How could you fix it?

Thanks
Albretch
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top