In-Depth Look at Schemas




One of the best ways to understand the XML schema language is to take a look at it; therefore, this section
provides you with a brief example of a simple XML schema document followed by the XML document
instance that conforms to the schema.

<?xml version=”1.0” encoding=”utf-8”?>
<xsd:schema

xmlns:xsd=”http://www.w3.org/2001/XMLSchema”
elementFormDefault=”qualified”
targetNamespace=”http://www.wrox.com/books/xml”
xmlns=”http://www.wrox.com/books/xml”>

<xsd:element name=”books”>

<xsd:complexType>

<xsd:sequence>

<xsd:element name=”book” maxOccurs=”unbounded”>

<xsd:complexType>

<xsd:sequence>

<xsd:element name=”title” type=”xsd:string”/>
<xsd:element name=”author” type=”xsd:string”/>

</xsd:sequence>

</xsd:complexType>

</xsd:element>

</xsd:sequence>

</xsd:complexType>

</xsd:element>
</xsd:schema>

Notice that schemas look similar to XML, and are usually longer than a DTD; typically, schemas are
longer because they contain more information. Here is the XML document instance that conforms to the
schema declaration.

<?xml version=”1.0”?>
<books>

<book>

<title>XSLT Programmers Reference</title>
<author>Michael Kay</author>

</book>

</books>