XML Schemas and Namespaces

Roger Costello costello at mitre.org
Fri Dec 31 12:56:34 GMT 1999

Hi Folks,

I have a couple of questions with regards to the use of namespaces in
XML Schemas.

1.  As has been recently discussed, the method for an XML instance
document to indicate the XML Schema that it conforms to is with the
schemaLocation attribute.  For example:

<?xml version="1.0"?>
<BookCatalogue xmlns:xsi="http://www.w3.org/1999/XMLSchema/instance"

At the root element (BookCatalogue) of this XML instance document I am
using schemaLocation to indicate the XML Schema that it conforms to.

The problem is this: when I defined BookCatalogue (in BookCatalogue.xsd)
I didn't define any attributes for it.  I certainly didn't define
xmlns:xsi nor xsi:schmemaLocation as attributes.  Thus, this XML
instance document is invalid, right?

The nice thing about DOCTYPE was that it separated the mechanism for
declaring the associated schema (i.e., the DTD) from the information
items (i.e., the elements).  With schemaLocation the mechanism for
declaring the associated schema is intertwined with the information

Thus, it seems that when an XML Schema is written the author must try to
anticipate how instance documents will use it and add in xmlns:xsi and
xsi:schemaLocation attributes to the elements being defined in the
schema.  For my example, I would need to define BookCatalogue as:

    <element name="BookCatalogue">
             <element ref="cat:Book" minOccurs="0" maxOccurs="*"/>
             <attribute name="xmlns:xsi" type="URI"/>
             <attribute name="xsi:schemaLocation" type="string"/>

I must be misunderstanding something fundamental.  This is obviously

2. My second question has to do with referencing elements within an XML
Schema.   Consider this schema:

<?xml version="1.0"?>
<!DOCTYPE schema SYSTEM "xml-schema.dtd"[
<!ATTLIST schema xmlns:cat CDATA #IMPLIED>
<schema xmlns="http://www.w3.org/1999/XMLSchema"
    <element name="BookCatalogue">
             <element ref="cat:Book" minOccurs="0" maxOccurs="*"/>
    <element name="Book">
            <element ref="cat:Title"/>
            <element ref="cat:Author"/>
            <element ref="cat:Date"/>
            <element ref="cat:ISBN"/>
            <element ref="cat:Publisher"/>
    <element name="Title" type="string"/>
    <element name="Author" type="string"/>
    <element name="Date" type="date"/>
    <element name="ISBN" type="string"/>
    <element name="Publisher" type="string"/>

Note that we define the Book element and in the BookCatalogue element it
is referenced using cat:Book

    <element name="BookCatalogue">
             <element ref="cat:Book" minOccurs="0" maxOccurs="*"/>

My understanding is that the reason for prefixing Book with cat: is to
indicate "the Book element that we are referencing comes from the cat:
namespace".   The cat: namespace is defined at the top of the schema to
be the same as the targetNamespace.  Thus, the cat: namespace refers to
this schema document.

Here's my question:  it appears to me that namespaces are being used
here to "point" to things.  In this case, cat: is "pointing" to the
current document (the XML Schema).  Isn't this a violation of the
namespace spec, which says that there is no guarantee that there is
anything at the URI referenced by a namespace?


xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev at ic.ac.uk
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/ and on CD-ROM/ISBN 981-02-3594-1
To unsubscribe, mailto:majordomo at ic.ac.uk the following message;
unsubscribe xml-dev
To subscribe to the digests, mailto:majordomo at ic.ac.uk the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa at ic.ac.uk)

More information about the Xml-dev mailing list