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: mrgla...@ca.ibm.com
E-mail: mrgla...@apache.org

Hansgerd Schneider <hansgerd.schnei...@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-unsubscr...@xerces.apache.org
> For additional commands, e-mail: j-users-h...@xerces.apache.org

Reply via email to