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

Discussion in 'Java' started by lbrtchx@hotmail.com, Aug 29, 2005.

  1. Guest

    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
     
    , Aug 29, 2005
    #1
    1. Advertising

  2. Roedy Green Guest

    On Mon, 29 Aug 2005 10:43:39 -0400, wrote or
    quoted :

    ><xsd:schema xmlns:xsd="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.
     
    Roedy Green, Aug 30, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Albretch
    Replies:
    0
    Views:
    323
    Albretch
    May 26, 2005
  2. Tony Prichard
    Replies:
    0
    Views:
    746
    Tony Prichard
    Dec 12, 2003
  3. Albretch
    Replies:
    1
    Views:
    404
    Martin Honnen
    May 26, 2005
  4. GenxLogic
    Replies:
    3
    Views:
    1,294
    andrewmcdonagh
    Dec 6, 2006
  5. Andy B
    Replies:
    0
    Views:
    380
    Andy B
    Aug 7, 2008
Loading...

Share This Page