These attributes both have default values of their own, which are:
elementFormDefault="unqualified" and
attributeFormDefault="unqualified". These values
are appropriate to the case in which only the document element uses a
namespace:
<lib:library xmlns:lib="http://dyomedea.com/ns/library">
<book id="b0836217462" available="yes">
<isbn>
0836217462
</isbn>
<title>
Being a Dog Is a Full-Time Job
</title>
</book>
</lib:library>
Since global elements and attributes must be qualified, defining this
schema as a single schema requires that all the elements and
attributes are locally defined.
<?xml version="1.0"?>
<xs:schema targetNamespace="http://dyomedea.com/ns/library"
elementFormDefault="qualified" attributeFormDefault="unqualified"
xmlns:lib="http://dyomedea.com/ns/library"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="library">
<xs:complexType>
<xs:sequence>
<xs:element name="book" type="lib:bookType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="born" type="xs:date"/>
<xs:element name="dead" type="xs:date" minOccurs="0"/>
<xs:element name="qualification" type="xs:string"
minOccurs="0"/>
</xs:sequence>
<xs:attribute name="id" type="xs:ID" use="required"/>
</xs:complexType>
</xs:element>
<xs:complexType name="bookType">
<xs:sequence>
<xs:element name="isbn" type="xs:NMTOKEN"/>
<xs:element name="title" type="xs:string"/>
<xs:element name="authors">
<xs:complexType>
<xs:sequence>
<xs:element ref="lib:person" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="characters">
<xs:complexType>
<xs:sequence>
<xs:element ref="lib:person" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="id" type="xs:ID" use="required"/>
<xs:attribute name="available" type="xs:string" use="required"/>
</xs:complexType>
</xs:schema>
In this example, the names of components defined by the schema are
always unprefixed when they are defined. Because this schema only
defines components in the single http://dyomedea.com/ns/library namespace
(identified as the targetNamespace attribute of
the xs:schema element), there isn't any risk of
confusion. The only other namespaces used here are the namespace for
W3C XML Schema itself, identified with an xs
prefix, and another mapping for the http://dyomedea.com/ns/library namespace,
using lib as the prefix. The
lib-prefixed form is used for cross-references
between declarations.
<?xml version="1.0"?>
<xs:schema targetNamespace="http://dyomedea.com/ns/library"
elementFormDefault="qualified" attributeFormDefault="unqualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://dyomedea.com/ns/library">
<xs:element name="library">
<xs:complexType>
<xs:sequence>
<xs:element name="book" type="bookType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="born" type="xs:date"/>
<xs:element name="dead" type="xs:date" minOccurs="0"/>
<xs:element name="qualification" type="xs:string"
minOccurs="0"/>
</xs:sequence>
<xs:attribute name="id" type="xs:ID" use="required"/>
</xs:complexType>
</xs:element>
<xs:complexType name="bookType">
<xs:sequence>
<xs:element name="isbn" type="xs:NMTOKEN"/>
<xs:element name="title" type="xs:string"/>
<xs:element name="authors">
<xs:complexType>
<xs:sequence>
<xs:element ref="person" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="characters">
<xs:complexType>
<xs:sequence>
<xs:element ref="person" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="id" type="xs:ID" use="required"/>
<xs:attribute name="available" type="xs:string" use="required"/>
</xs:complexType>
</xs:schema>
In this version, all references to W3C XML Schema's
own elements are still made using the xs prefix.
Names of components are still unprefixed, but the
lib prefix is now unnecessary, so all of those
prefixes can disappear. Because the default namespace is defined in
this document, W3C XML Schema will understand the connection between
the components it defines and references to those components.