W3C home > Mailing lists > Public > www-xml-schema-comments@w3.org > April to June 2000

LC-98. ns-and-schemaloc: Clarifying schema location and namespace

From: David Ezell <David_E3@Verifone.Com>
Date: Fri, 9 Jun 2000 08:22:23 -0400
Message-ID: <472E220BA79DD11186340060B06B38D9033ACCC9@tpantmail1.ssr.hp.com>
To: "'gmacri@libero.it'" <gmacri@libero.it>
Cc: "'www-xml-schema-comments@w3.org'" <www-xml-schema-comments@w3.org>
"gmacri@libero.it"<gmacri@libero.it> to XML Schema Comments list, Sat, 6 May
2000 14:20:01 +0200:
>  In this example there are three declarations of namespace and two declaration
of schemalocation that are independent. 
>  <Library 
>       xmlns:book  ="http://www.somewhere.org/Book" 
>       xmlns:person="http://www.somewhere-else.org/Person" 
>       xmlns:xsi   ="http://www.w3.org/1999/XMLSchema/instance" 
>       xsi:schemaLocation="http://www.somewhere.org/Examples 
>         http://www.somewhere.org/Examples/Book.xsd 
>         http://www.somewhere-else.org/Person 
>         http://www.somewhere-else.org/Person/Person.xsd">
>     <BookCatalogue>
>       <book:Book>
>            <book:Title>Illusions The Adventures of a Reluctant 
>              Messiah</book:Title> 
>            <book:Author>Richard Bach</book:Author> 
>            <book:Date>1977</book:Date> 
>            <book:ISBN>0-440-34319-4</book:ISBN> 
>            <book:Publisher>Dell Publishing Co.</book:Publisher> 
>        </book:Book>
>  When I analyze this document with an application (automatically), how I can
understand that, for example, 
>  for "Book" element I must search it in the schema "Book.xsd" and not in
"Person.xsd", to verify the validity of this document? 

Thanks for the question.  Associating a schema to a namespace while avoiding
conflict with the stated intent of the Namespace specification does take a
couple of steps, but it's really not too complex.

The example above is only slightly wrong:

>  <Library        xsi:schemaLocation="http://www.somewhere.org/Examples 
>         http://www.somewhere.org/Examples/Book.xsd 
>         http://www.somewhere-else.org/Person 
>         http://www.somewhere-else.org/Person/Person.xsd">

should be:

   <Library        xsi:schemaLocation="http://www.somewhere.org/Book

Note that the first entry in the schemaLocation attribute has been changed to
"Book" from "Examples".  The entries in the "xsi:schemaLocation" attribute in
the instance document are namespace/location pairs; in the case of the namespace
"http://www.somewhere.org/Book" the schema location hint is

Further, the schema itself will name a target namespace, which must match the
namespace described in the instance document, for example:

   <xsd:schema xsd:targetNamespace="http://www.somewhere.org/Book" 
         xmlns:xsd="http://www.w3.org/1999/XMLSchema" >

         <element name="Book" xsd:type="local:BookType" />

         <complexType name="BookType">
              <element name="Title" xsd:type="string" />

Whether schemas are loaded from the "schemaLocation" hints is at processor
discretion; the designed {targetNamespace} for the schema must simply match one
of the referenced namespaces (prefixed or not) in the document for its
components to be used.  As Henry Thompson noted earlier, the processor may opt
not to load any schema:  it may already know what schema to use for a designated

While this two step process of element bound to namespace followed by namespace
bound to schema location may seem cumbersome, it appropriately and effectively
decouples namespace definitions from the locations of schemas which fill them
with names.

One additional point:  to provide a location hint for a schema document with the
"no namespace" elements in an instance document (i.e. no prefixes), use the
"xsi:noNamespaceSchemaLocation" attribute instead of the "xsi:schemaLocation"
attribute.  A slight modification of your intial example follows:

       xmlns:book  ="http://www.somewhere.org/Book" 
       xmlns:xsi   ="http://www.w3.org/1999/XMLSchema/instance" 
            <Title>Illusions The Adventures of a Reluctant 
            <Author>Richard Bach</Author> 
            <Publisher>Dell Publishing Co.</Publisher> 
Of course, "BookCatalog" would also be expected to be in the schema now, but
we've given the processor a hint at where to find elements and attributes which
appear to have no namespace (i.e. prefix).

Thanks for taking the time to comment.  I hope this explanation helps.  

-David Ezell
for the W3C XML Schema Working Group
Received on Friday, 9 June 2000 09:34:39 UTC

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