Using W3C XML Schema
by Eric van der Vlist
|
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9
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 on some extensions that you can use within your instance
documents. In order to differentiate these other features, a separate
namespace, http://www.w3.org/2001/XMLSchema-instance, usually
associated with the prefix xsi.
The xsi:noNamespaceSchemaLocation and xsi:schemaLocation attributes allow you to tie a document to its W3C XML Schema. This link is not
mandatory, and other indications can be given at validation time, 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/2001/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 whitespace in the same attribute):
<book isbn="0836217462" xmlns="http://example.org/ns/books/" xmlns:xsi="http://www.w3.org/2001/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:nil, which lets you specify a nil (null) value for an element (that has to be defined as nillable in
the schema using a nillable=true attribute). You don't need to declare these attributes in your W3C XML Schema to be able
to use them in an instance document.