Chaining <xs:import> statements

I have a situation where my schema imports a schema (parent) which, in turn,
imports another schema (child).  I am referencing elements from both schemas
in my schema but only importing the (parent) schema while declaring both
namespaces in my schema.

 

What I have found is the .NET implementation of XML Schema complains about
this with the following warning:

 

"Namespace 'baseURI' is not available to be referenced in this schema."

 

The schema still properly validates the document even items coming from the
(child) schema, but the warning concerns me.  If I <import> the (child) in
my schema the warning goes away, but this also seems incorrect - would I not
be importing the schema twice (implementation issues aside)?

 

What should be correct way to handle this situation?

 

Here is a simple contrived example that demonstrates the issue:

 

Base.xsd

<?xml version="1.0" encoding="UTF-8"?>

<xs:schema elementFormDefault="qualified" attributeFormDefault="unqualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="baseURI"      >

            <xs:complexType name="baseType">

                        <xs:sequence    >

                                    <xs:element name="name"
type="xs:string"/>

                                    <xs:element name="age" type="xs:int" />

                        </xs:sequence   >          

            </xs:complexType>

</xs:schema>

 

Composite.xsd

<?xml version="1.0" encoding="UTF-8"?>

<xs:schema elementFormDefault="qualified" attributeFormDefault="unqualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="compositeURI"


 xmlns:b="baseURI">

<xs:import schemaLocation="base.xsd" namespace="baseURI"/> 

            <xs:complexType name="composite">

                                    <xs:sequence maxOccurs="unbounded"  >

                                                <xs:element name="person"
type="b:baseType" />

                                                <xs:element name="reference"
type="b:baseType" />

                                    </xs:sequence> 

            </xs:complexType>       

</xs:schema>

 

Interview.xsd

<?xml version="1.0" encoding="UTF-8"?>

<xs:schema elementFormDefault="qualified" attributeFormDefault="unqualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:b="baseURI"
xmlns:c="compositeURI">

            <xs:import namespace="compositeURI"
schemaLocation="composite.xsd"            />

            <!-- warning unless uncommented -->

            <!-- xs:import namespace="baseURI" schemaLocation="base.xsd"
/ -->

            <xs:element name="root" type="people"  />

            <xs:complexType name="people">

                        <xs:sequence maxOccurs="10">

                            <xs:element name="interviewer" type="b:baseType"
/>

                                    <xs:element name="candidate"
type="c:composite" />

                        </xs:sequence>

            </xs:complexType>       

</xs:schema>

 

Instance.xml

<?xml version="1.0" encoding="UTF-8"?>

<!--Sample XML file generated by XMLSPY v2004 rel. 4 U
(http://www.xmlspy.com)-->

<root xmlns:b="baseURI" xmlns:c="compositeURI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="interview.xsd">

            <interviewer>

                        <b:name>Hal</b:name>

                        <b:age>36</b:age>        

            </interviewer>

            <candidate>

                        <c:person>

                                    <b:name>Dave</b:name>           

                                    <b:age>45</b:age>        

                        </c:person>

                        <c:reference>

                                    <b:name>Frank</b:name>         

                                    <b:age>51</b:age>        

                        </c:reference>

            </candidate>

</root>

 

Thanks!

 

James Delmerico

Senior Technical Architect, IPS-Sendero

(770) 409-0047 x437

230 Scientific Dr, Suite 800

Norcross, GA  30092

 

Received on Tuesday, 22 June 2004 12:13:16 UTC