Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > "root element collision" while trying use commonality in two XML schemas

Reply
Thread Tools

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

 
 
lbrtchx@hotmail.com
Guest
Posts: n/a
 
      08-29-2005
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 xmlnssd="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 xmlnssd="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 xmlnssd="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.detect RootElementCollisions(GrammarInfoFacade.java:114)
at
jaxb.NQItm00.impl.runtime.GrammarInfoFacade.<init> (GrammarInfoFacade.java:35)
at
jaxb.NQItm00.impl.runtime.GrammarInfoFacade.create GrammarInfoFacade(GrammarInfoFacade.java:185)
at
jaxb.NQItm00.impl.runtime.DefaultJAXBContextImpl.< init>(DefaultJAXBContextImpl.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInsta nce(NativeConstructorAccessorImpl.java:39)
at
sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Construc tor.java:494)
at
com.sun.xml.bind.ContextFactory_1_0_1.createContex t(ContextFactory_1_0_1.java:50)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at javax.xml.bind.ContextFinder.newInstance(ContextFi nder.java:96)
at javax.xml.bind.ContextFinder.searchcontextPath(Con textFinder.java:229)
at javax.xml.bind.ContextFinder.find(ContextFinder.ja va: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.createContex t(ContextFactory_1_0_1.java:56)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at javax.xml.bind.ContextFinder.newInstance(ContextFi nder.java:96)
at javax.xml.bind.ContextFinder.searchcontextPath(Con textFinder.java:229)
at javax.xml.bind.ContextFinder.find(ContextFinder.ja va:149)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Why is this happening? How could you fix it?

Thanks
Albretch

 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      08-30-2005
On Mon, 29 Aug 2005 10:43:39 -0400, wrote or
quoted :

><xsd:schema xmlnssd="http://www.w3.org/2001/XMLSchema">
> <xsd:include schemaLocation="commons00.xsd"/>


What happens if you expand the schema includes manually?
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can xml schemas from a dataset be used to validate standard xml files? Andy B ASP .Net 0 08-06-2008 11:42 PM
how to Update/insert an xml element's text----> (<element>text</element>) HANM XML 2 01-29-2008 03:31 PM
handling commonality in similar XSD schemas Albretch XML 1 05-26-2005 05:16 PM
handling commonality in similar XSD schemas Albretch Java 0 05-26-2005 04:53 PM
Help on including one XML document within another XML document using XML Schemas Tony Prichard XML 0 12-12-2003 03:18 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57