home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Book HomeXML in a NutshellSearch this book

21.4. Instance Document Attributes

The W3C XML Schema Language defines four attributes in the http://www.w3.org/2001/XMLSchema-instance namespace (here mapped to the xsi prefix), which are attached to elements in the instance document rather than elements in the schema. These are as follows: xsi:nil, xsi:type, xsi:schemaLocation, and xsi:noNamespaceSchemaLocation. All four of these attributes are special in that the schemas do not need to declare them.

xsi:schemaLocation

The xsi:schemaLocation attribute locates schemas for elements and attributes that are in a specified namespace. Its value is a namespace URI followed by a relative or absolute URL where the schema for that namespace can be found. It is most commonly attached to the root element but can appear further down the tree. For example, this person element in the http://www.cafeconleche.org/namespaces/person namespace claims that it should be validated against the schema found at the URL http://www.elharo.com/person.xs:

<person xmlns="http://www.cafeconleche.org/namespaces/person"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.cafeconleche.org/namespaces/person
                      http://www.elharo.com/person.xs">
  <name>
    <first_name>Alan</first_name>
    <last_name>Turing</last_name>
  </name>
  <profession>computer scientist</profession>
  <profession>mathematician</profession>
  <profession>cryptographer</profession>
</person>

If more than one namespace is used in a document, then each namespace must have its own schema. The namespace URIs and schema URLs can be listed in sequence in the same xsi:schemaLocation attribute. For example, the xsi:schemaLocation attribute on this person element says that items from the http://www.cafeconleche.org/namespaces/person namespace should be validated against the schema found at the URL http://www.elharo.com/person.xs, while items from the http://www.cafeconleche.org/namespaces/names namespace should be validated against the schema found at the relative URL names.xs.

<person xmlns="http://www.cafeconleche.org/namespaces/person"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.cafeconleche.org/namespaces/person
                      http://www.elharo.com/person.xs
                      http://www.cafeconleche.org/namespaces/names
                      names.xs">
  <name xmlns="http://www.cafeconleche.org/namespaces/names">
    <first_name>Alan</first_name>
    <last_name>Turing</last_name>
  </name>
  <profession>computer scientist</profession>
  <profession>mathematician</profession>
  <profession>cryptographer</profession>
</person>

These are only suggestions. Schema processors are allowed to use other means of locating the relevant schemas and to ignore the hints provided by xsi:schemaLocation.



Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.