XML Schema Question: How to indicate an XML document conforms to an XML Schema

Roger L. Costello costello at mitre.org
Wed Dec 29 12:56:58 GMT 1999


Hi Folks,

Thanks for the pointer to the location in the XML Schema spec where they
discuss how an XML instance document is to reference an XML Schema
(4.3.2).  I have read it over and wish to confirm my understanding.

I would like to first see if I understand the simple case of how to
indicate in an XML document that it conforms to a single XML Schema. 

Example.  Suppose that I create an XML Schema for BookCatalogues 
(called BookCatalogue.xsd):

<?xml version="1.0"?>
<!DOCTYPE schema SYSTEM "xml-schema.dtd">
<schema xmlns="http://www.w3.org/1999/XMLSchema"
        targetNamespace="http://www.somewhere.org/BookCatalogue">
     ...
</schema>

In my XML document I indicate that it conforms to this XML Schema using
the schemaLocation attribute:

<?xml version="1.0"?>
<BookCatalogue 
          xmlns:xsi="http://www.w3.org/1999/XMLSchema/instance"
          xsi:schemaLocation=
              "http://www.somewhere.org/BookCatalogue
              http://www.somewhere.org/BookCatalogue/BookCatalogue.xsd">
    <Book>
        <Title>Illusions The Adventures of a Reluctant Messiah</Title>
        <Author>Richard Bach</Author>
        <Date>1977</Date>
        <ISBN>0-440-34319-4</ISBN>
        <Publisher>Dell Publishing Co.</Publisher>
    </Book>
    ...
</BookCatalogue>

In the BookCatalogue element (the root element) I declare that the
schemaLocation attribute comes from the XML Schema Instance namespace
(xsi).  The value of the schemaLocation attribute is a pair of values -
a namespace and the URI to a schema.  When the XML Parser processes this
XML document it will use the schemaLocation pair of values to determine
the XML Schema that it conforms to.  It will retrieve the schema at the
URI specified in schemaLocation (in this example, BookCatalogue.xsd) and
then it will open up this schema document to confirm that its
targetNamespace value matches the namespace value shown in
schemaLocation.  In this example it does.  Thus, the XML Parser knows
that "All the stuff between <BookCatalogue> and </BookCatalogue>
conforms to the schema defined at this URI with this namespace."

Is this a correct understanding of how to indicate in an XML document
that it conforms to a particular XML Schema?  /Roger


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