[XMLSCHEMA-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Why can an element in an included no-namespace schema reference a type in the including schema when there is no default namespace declaration?

From: Costello, Roger L. <costello@mitre.org>
Date: Sat, 28 Jan 2012 23:00:24 +0000
To: "xmlschema-dev@w3.org" <xmlschema-dev@w3.org>
Message-ID: <B5FEE00B53CF054AA8439027E8FE1775181FECF4@IMCMBX04.MITRE.ORG>
Why can an element in an included no-namespace schema reference a  type in the including schema when there is no default namespace declaration?
Hi Folks,

The following schema document is erroneous because the element A1 is trying to reference a type XYZ in no-namespace:

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

    <xs:include schemaLocation="B.xsd"/>

    <xs:simpleType name="XYZ">
        <xs:restriction base="xs:string">
            <xs:maxLength value="10"/>
        </xs:restriction>
    </xs:simpleType>
    
    <xs:element name="A1" type="XYZ" />
    
</xs:schema>
----------------------------------------------------------------------

The error is fixed by adding a default namespace declaration:

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

    <xs:include schemaLocation="B.xsd"/>

    <xs:simpleType name="XYZ">
        <xs:restriction base="xs:string">
            <xs:maxLength value="10"/>
        </xs:restriction>
    </xs:simpleType>
    
    <xs:element name="A1" type="XYZ" />
    
</xs:schema>
----------------------------------------------------------------------

Good.

Now let's remove the element A1 and remove the default namespace declaration. This is a valid schema:

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

    <xs:include schemaLocation="B.xsd"/>

    <xs:simpleType name="XYZ">
        <xs:restriction base="xs:string">
            <xs:maxLength value="10"/>
        </xs:restriction>
    </xs:simpleType>
    
</xs:schema>
----------------------------------------------------------------------

Notice that the schema document includes B.xsd. Let's look at it. It is a no-namespace schema document:

B.xsd
----------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
    
    <xs:element name="B2" type="XYZ" />
    
</xs:schema>
----------------------------------------------------------------------

Since A.xsd has a targetNamespace the B.xsd schema document is namespace-coerced to the namespace of A.xsd.

Observe that element B2 references type XYZ which is in A.xsd.

When I validate A.xsd it validates fine.

Hey!  How can that be?

Recall that I removed the default namespace declaration from A.xsd. 

Why can element B2 reference type XYZ without a default namespace declaration but element A1 couldn't?

/Roger
Received on Saturday, 28 January 2012 23:01:00 GMT

Subscribe to the Stylus Scoop newsletter for helpful XML tips and tutorials.
Email
First Name
Last Name
Company

Download Stylus Studio 6 XML Enterprise Edition

Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.