W3C home > Mailing lists > Public > www-xml-schema-comments@w3.org > October to December 1999

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

From: Roger L. Costello <costello@mitre.org>
Date: Wed, 29 Dec 1999 07:58:15 -0500
Message-ID: <386A0567.4ECA0C06@mitre.org>
To: xml-dev@ic.ac.uk
CC: www-xml-schema-comments@w3c.org, "Schneider,John C." <jcs@mitre.org>, "Cokus,Michael S." <msc@mitre.org>, "Costello,Roger L." <costello@mitre.org>
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
Received on Wednesday, 29 December 1999 07:56:50 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 23:08:45 UTC