You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Hansgerd Schneider <ha...@gmx.de> on 2010/04/11 19:53:06 UTC

Problem with a xsd that imports another xsd which again imports another one

Hi

I need some help with a problem that i ran into. I've created a simple 
example to demonstrate it.

There are 3 xsd files with two different targetNamespaces nsA and nsB. I 
pasted them at the end of this mail.
The files use imports in the following way:

 xsd1(nsA) imports xsd2(nsB) imports xsd3(nsA)

A complexType (Type3) is defined in xsd3.
This is extended by a complexType (Type2) in xsd2.
This is extended by a complexType (Type1) in xsd1.

If i validate these files with XMLSpy, i get the message that these are 
all valid xml-schema files.
I do believe that they are valid too, but...

If i try to load xsd1 with SchemaFactory.getSchema(...) (Xerces 2.9.1) 
oder try to run xjc with it, i get the following error message:
[ERROR] src-resolve: Cannot resolve the name 'a:Type3' to a(n) 'type 
definition' component.
  line 11 of file:/home/hansgerd/xml/examples/ex1/xsd2.xsd

If i uncomment the xs:include of xsd3 in xsd1 everything works fine with 
no error.

I don't understand what's wrong with these xsd files and why XMLSpy 
comes to a different result than Xerces.
Which one ist correct? XMLSpy oder Xerces?

These are the contents of my xsd files.

File: ./xsd1.xsd targetNamespace="nsA"
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:b="nsB" targetNamespace="nsA"
    elementFormDefault="qualified"
    attributeFormDefault="unqualified">
 
    <xs:import namespace="nsB" schemaLocation="xsd2.xsd"/>
<!--    <xs:include schemaLocation="xsd3.xsd"/> -->

    <xs:complexType name="Type1">
        <xs:complexContent>
            <xs:extension base="b:Type2"/>
        </xs:complexContent>
    </xs:complexType>

</xs:schema>

File: ./xsd2.xsd targetNamespace="nsB"
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="nsB"
    xmlns:a="nsA"
    elementFormDefault="qualified"
    attributeFormDefault="unqualified">

    <xs:import namespace="nsA" schemaLocation="xsd3.xsd"/>
 
    <xs:complexType name="Type2">
        <xs:complexContent>
            <xs:extension base="a:Type3"/>
        </xs:complexContent>
    </xs:complexType>

</xs:schema>

File: ./xsd3.xsd targetNamespace="nsA"
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="nsA"
    elementFormDefault="qualified"
    attributeFormDefault="unqualified">

    <xs:complexType name="Type3"/>

</xs:schema>

Thanks,

Hansgerd Schneider

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: Problem with a xsd that imports another xsd which again imports another one

Posted by Hansgerd Schneider <ha...@gmx.de>.
Hi Michael

I've enabled this feature and now everything is working fine.

Thank you very much for your quick answer.

Hansgerd

Michael Glavassevich wrote:
>
> Hi Hansgerd,
>
> XML Schema processors are not required to follow an import for a 
> namespace it's already seen and Xerces will not follow such imports by 
> default. You would need to enable the "honour-all-schemaLocations" [1] 
> feature to get the behaviour you want or add an include to "xsd3.xsd" 
> in "xsd1.xsd" (as you've already discovered). The latter solution 
> being the one I would go with if I were publishing my schema for 
> others to use with potentially any XML Schema processor (not just 
> Xerces or XMLSpy).
>
> Thanks.
>
> [1] 
> http://xerces.apache.org/xerces2-j/features.html#honour-all-schemaLocations
>
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: mrglavas@ca.ibm.com
> E-mail: mrglavas@apache.org
>
> Hansgerd Schneider <ha...@gmx.de> wrote on 04/11/2010 
> 01:53:06 PM:
>
> > Hi
> >
> > I need some help with a problem that i ran into. I've created a simple
> > example to demonstrate it.
> >
> > There are 3 xsd files with two different targetNamespaces nsA and 
> nsB. I
> > pasted them at the end of this mail.
> > The files use imports in the following way:
> >
> >  xsd1(nsA) imports xsd2(nsB) imports xsd3(nsA)
> >
> > A complexType (Type3) is defined in xsd3.
> > This is extended by a complexType (Type2) in xsd2.
> > This is extended by a complexType (Type1) in xsd1.
> >
> > If i validate these files with XMLSpy, i get the message that these are
> > all valid xml-schema files.
> > I do believe that they are valid too, but...
> >
> > If i try to load xsd1 with SchemaFactory.getSchema(...) (Xerces 2.9.1)
> > oder try to run xjc with it, i get the following error message:
> > [ERROR] src-resolve: Cannot resolve the name 'a:Type3' to a(n) 'type
> > definition' component.
> >   line 11 of file:/home/hansgerd/xml/examples/ex1/xsd2.xsd
> >
> > If i uncomment the xs:include of xsd3 in xsd1 everything works fine 
> with
> > no error.
> >
> > I don't understand what's wrong with these xsd files and why XMLSpy
> > comes to a different result than Xerces.
> > Which one ist correct? XMLSpy oder Xerces?
> >
> > These are the contents of my xsd files.
> >
> > File: ./xsd1.xsd targetNamespace="nsA"
> > <?xml version="1.0" encoding="UTF-8"?>
> > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> >     xmlns:b="nsB" targetNamespace="nsA"
> >     elementFormDefault="qualified"
> >     attributeFormDefault="unqualified">
> >  
> >     <xs:import namespace="nsB" schemaLocation="xsd2.xsd"/>
> > <!--    <xs:include schemaLocation="xsd3.xsd"/> -->
> >
> >     <xs:complexType name="Type1">
> >         <xs:complexContent>
> >             <xs:extension base="b:Type2"/>
> >         </xs:complexContent>
> >     </xs:complexType>
> >
> > </xs:schema>
> >
> > File: ./xsd2.xsd targetNamespace="nsB"
> > <?xml version="1.0" encoding="UTF-8"?>
> > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> >     targetNamespace="nsB"
> >     xmlns:a="nsA"
> >     elementFormDefault="qualified"
> >     attributeFormDefault="unqualified">
> >
> >     <xs:import namespace="nsA" schemaLocation="xsd3.xsd"/>
> >  
> >     <xs:complexType name="Type2">
> >         <xs:complexContent>
> >             <xs:extension base="a:Type3"/>
> >         </xs:complexContent>
> >     </xs:complexType>
> >
> > </xs:schema>
> >
> > File: ./xsd3.xsd targetNamespace="nsA"
> > <?xml version="1.0" encoding="UTF-8"?>
> > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> >     targetNamespace="nsA"
> >     elementFormDefault="qualified"
> >     attributeFormDefault="unqualified">
> >
> >     <xs:complexType name="Type3"/>
> >
> > </xs:schema>
> >
> > Thanks,
> >
> > Hansgerd Schneider
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> > For additional commands, e-mail: j-users-help@xerces.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: Problem with a xsd that imports another xsd which again imports another one

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Jitendra.Kotamraju@Sun.COM wrote on 04/12/2010 02:02:23 PM:

> Michael Glavassevich wrote:
> >
> > Hi Hansgerd,
> >
> > XML Schema processors are not required to follow an import for a
> > namespace it's already seen and Xerces will not follow such imports by
> > default. You would need to enable the "honour-all-schemaLocations" [1]
> > feature to get the behaviour you want or add an include to "xsd3.xsd"
> > in "xsd1.xsd" (as you've already discovered). The latter solution
> > being the one I would go with if I were publishing my schema for
> > others to use with potentially any XML Schema processor (not just
> > Xerces or XMLSpy).
> >
> Even this latter solution doesn't seem to work with JDK5( but works with
> JDK6). Is that correct ? The reason may be that JDK5 is using older
> xerces version.

I wouldn't know. I never use either version. What gets included in the JDK
has been forked and changed in all sorts of ways that we wouldn't be aware
of. I can only speak for what Apache Xerces does.

> thanks,
> Jitu
> >
> >
> > Thanks.
> >
> > [1]
> >
http://xerces.apache.org/xerces2-j/features.html#honour-all-schemaLocations
> >
> > Michael Glavassevich
> > XML Parser Development
> > IBM Toronto Lab
> > E-mail: mrglavas@ca.ibm.com
> > E-mail: mrglavas@apache.org

Thanks.

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

Re: Problem with a xsd that imports another xsd which again imports another one

Posted by Michael Ludwig <mi...@gmx.de>.
Jitendra Kotamraju schrieb am 12.04.2010 um 11:02:23 (-0700):
[Re: Problem with a xsd that imports another xsd which again imports
another one]

> Even this latter solution doesn't seem to work with JDK5( but works
> with JDK6). Is that correct ? The reason may be that JDK5 is using
> older xerces version.

You might consider filing a bug with http://bugs.sun.com/ , which is how
this unfortunate JDK parser situation might eventually be improved.

-- 
Michael Ludwig

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: Problem with a xsd that imports another xsd which again imports another one

Posted by Jitendra Kotamraju <ji...@oracle.com>.
Michael Glavassevich wrote:
>
> Hi Hansgerd,
>
> XML Schema processors are not required to follow an import for a 
> namespace it's already seen and Xerces will not follow such imports by 
> default. You would need to enable the "honour-all-schemaLocations" [1] 
> feature to get the behaviour you want or add an include to "xsd3.xsd" 
> in "xsd1.xsd" (as you've already discovered). The latter solution 
> being the one I would go with if I were publishing my schema for 
> others to use with potentially any XML Schema processor (not just 
> Xerces or XMLSpy).
>
Even this latter solution doesn't seem to work with JDK5( but works with 
JDK6). Is that correct ? The reason may be that JDK5 is using older 
xerces version.

thanks,
Jitu
>
>
> Thanks.
>
> [1] 
> http://xerces.apache.org/xerces2-j/features.html#honour-all-schemaLocations
>
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: mrglavas@ca.ibm.com
> E-mail: mrglavas@apache.org
>
> Hansgerd Schneider <ha...@gmx.de> wrote on 04/11/2010 
> 01:53:06 PM:
>
> > Hi
> >
> > I need some help with a problem that i ran into. I've created a simple
> > example to demonstrate it.
> >
> > There are 3 xsd files with two different targetNamespaces nsA and 
> nsB. I
> > pasted them at the end of this mail.
> > The files use imports in the following way:
> >
> >  xsd1(nsA) imports xsd2(nsB) imports xsd3(nsA)
> >
> > A complexType (Type3) is defined in xsd3.
> > This is extended by a complexType (Type2) in xsd2.
> > This is extended by a complexType (Type1) in xsd1.
> >
> > If i validate these files with XMLSpy, i get the message that these are
> > all valid xml-schema files.
> > I do believe that they are valid too, but...
> >
> > If i try to load xsd1 with SchemaFactory.getSchema(...) (Xerces 2.9.1)
> > oder try to run xjc with it, i get the following error message:
> > [ERROR] src-resolve: Cannot resolve the name 'a:Type3' to a(n) 'type
> > definition' component.
> >   line 11 of file:/home/hansgerd/xml/examples/ex1/xsd2.xsd
> >
> > If i uncomment the xs:include of xsd3 in xsd1 everything works fine 
> with
> > no error.
> >
> > I don't understand what's wrong with these xsd files and why XMLSpy
> > comes to a different result than Xerces.
> > Which one ist correct? XMLSpy oder Xerces?
> >
> > These are the contents of my xsd files.
> >
> > File: ./xsd1.xsd targetNamespace="nsA"
> > <?xml version="1.0" encoding="UTF-8"?>
> > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> >     xmlns:b="nsB" targetNamespace="nsA"
> >     elementFormDefault="qualified"
> >     attributeFormDefault="unqualified">
> >  
> >     <xs:import namespace="nsB" schemaLocation="xsd2.xsd"/>
> > <!--    <xs:include schemaLocation="xsd3.xsd"/> -->
> >
> >     <xs:complexType name="Type1">
> >         <xs:complexContent>
> >             <xs:extension base="b:Type2"/>
> >         </xs:complexContent>
> >     </xs:complexType>
> >
> > </xs:schema>
> >
> > File: ./xsd2.xsd targetNamespace="nsB"
> > <?xml version="1.0" encoding="UTF-8"?>
> > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> >     targetNamespace="nsB"
> >     xmlns:a="nsA"
> >     elementFormDefault="qualified"
> >     attributeFormDefault="unqualified">
> >
> >     <xs:import namespace="nsA" schemaLocation="xsd3.xsd"/>
> >  
> >     <xs:complexType name="Type2">
> >         <xs:complexContent>
> >             <xs:extension base="a:Type3"/>
> >         </xs:complexContent>
> >     </xs:complexType>
> >
> > </xs:schema>
> >
> > File: ./xsd3.xsd targetNamespace="nsA"
> > <?xml version="1.0" encoding="UTF-8"?>
> > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> >     targetNamespace="nsA"
> >     elementFormDefault="qualified"
> >     attributeFormDefault="unqualified">
> >
> >     <xs:complexType name="Type3"/>
> >
> > </xs:schema>
> >
> > Thanks,
> >
> > Hansgerd Schneider
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> > For additional commands, e-mail: j-users-help@xerces.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: Problem with a xsd that imports another xsd which again imports another one

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hi Hansgerd,

XML Schema processors are not required to follow an import for a namespace
it's already seen and Xerces will not follow such imports by default. You
would need to enable the "honour-all-schemaLocations" [1] feature to get
the behaviour you want or add an include to "xsd3.xsd" in "xsd1.xsd" (as
you've already discovered). The latter solution being the one I would go
with if I were publishing my schema for others to use with potentially any
XML Schema processor (not just Xerces or XMLSpy).

Thanks.

[1]
http://xerces.apache.org/xerces2-j/features.html#honour-all-schemaLocations

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

Hansgerd Schneider <ha...@gmx.de> wrote on 04/11/2010 01:53:06
PM:

> Hi
>
> I need some help with a problem that i ran into. I've created a simple
> example to demonstrate it.
>
> There are 3 xsd files with two different targetNamespaces nsA and nsB. I
> pasted them at the end of this mail.
> The files use imports in the following way:
>
>  xsd1(nsA) imports xsd2(nsB) imports xsd3(nsA)
>
> A complexType (Type3) is defined in xsd3.
> This is extended by a complexType (Type2) in xsd2.
> This is extended by a complexType (Type1) in xsd1.
>
> If i validate these files with XMLSpy, i get the message that these are
> all valid xml-schema files.
> I do believe that they are valid too, but...
>
> If i try to load xsd1 with SchemaFactory.getSchema(...) (Xerces 2.9.1)
> oder try to run xjc with it, i get the following error message:
> [ERROR] src-resolve: Cannot resolve the name 'a:Type3' to a(n) 'type
> definition' component.
>   line 11 of file:/home/hansgerd/xml/examples/ex1/xsd2.xsd
>
> If i uncomment the xs:include of xsd3 in xsd1 everything works fine with
> no error.
>
> I don't understand what's wrong with these xsd files and why XMLSpy
> comes to a different result than Xerces.
> Which one ist correct? XMLSpy oder Xerces?
>
> These are the contents of my xsd files.
>
> File: ./xsd1.xsd targetNamespace="nsA"
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
>     xmlns:b="nsB" targetNamespace="nsA"
>     elementFormDefault="qualified"
>     attributeFormDefault="unqualified">
>
>     <xs:import namespace="nsB" schemaLocation="xsd2.xsd"/>
> <!--    <xs:include schemaLocation="xsd3.xsd"/> -->
>
>     <xs:complexType name="Type1">
>         <xs:complexContent>
>             <xs:extension base="b:Type2"/>
>         </xs:complexContent>
>     </xs:complexType>
>
> </xs:schema>
>
> File: ./xsd2.xsd targetNamespace="nsB"
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
>     targetNamespace="nsB"
>     xmlns:a="nsA"
>     elementFormDefault="qualified"
>     attributeFormDefault="unqualified">
>
>     <xs:import namespace="nsA" schemaLocation="xsd3.xsd"/>
>
>     <xs:complexType name="Type2">
>         <xs:complexContent>
>             <xs:extension base="a:Type3"/>
>         </xs:complexContent>
>     </xs:complexType>
>
> </xs:schema>
>
> File: ./xsd3.xsd targetNamespace="nsA"
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
>     targetNamespace="nsA"
>     elementFormDefault="qualified"
>     attributeFormDefault="unqualified">
>
>     <xs:complexType name="Type3"/>
>
> </xs:schema>
>
> Thanks,
>
> Hansgerd Schneider
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org