XML.com: XML From the Inside Out
oreilly.comSafari Bookshelf.Conferences.

advertisement

Using W3C XML Schema - Part 2
by Eric van der Vlist | Pages: 1, 2, 3, 4, 5

W3C XML Schema and Instance Documents

Table of Contents

Content Types
Constraints
Building Usable and Reusable Schemas
Namespaces
W3C XML Schema and Instance Documents

We've now covered most of the features of W3C XML Schema, but we still need to have a glance at some extensions that you can use within your instance documents. In order to differentiate these other features, a separate namespace, http://www.w3.org/2000/10/XMLSchema-instance, is used, usually associated with the prefix xsi.

The xsi:schemaLocation and xsi:noNamespaceSchemaLocation attributes allow you to tie a document to its W3C XML Schema. This link is not mandatory, and other indications can be given using application-dependent mechanisms (such as a parameter on a command line), but it does help W3C XML Schema aware tools to locate a schema.

Dependent on using namespaces, the link will be either

<book isbn="0836217462"
	xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
	xsi:noNamespaceSchemaLocation="file:library.xsd">

Or, as below (noting the syntax, with a URI for the namespace and the URI of the schema separated by a whitespace in the same attribute)

<book isbn="0836217462" xmlns="http://example.org/ns/books/"
	xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
	xsi:schemaLocation="http://example.org/ns/books/ file:library.xsd">

The other use of xsi attributes is to provide information about how an element corresponds to a schema. These attributes are xsi:type, which lets you define the simple or complex type of an element, and xsi:null, which lets you specify a null value for an element (that has to be defined as nullable="true" in the schema). You don't need to declare these attributes in your schema to be able to use them in an instance document.