Datasheet
❑ Because the schema is written in XML, you don’t have to know an archaic language to describe
your document. Because you already know XML, using XSD schema is fairly easy and straight-
forward.
❑ The same engines to parse XML documents can also be used to parse schemas.
❑ Just as you can parse schemas in the same fashion as XML, you can also add nodes, attributes,
and elements to schemas in the same manner.
❑ Schemas are widely accepted by most major parsing engines.
❑ Schemas allow you to data type with many different types. DTD only allows type content to be
a string.
Now that you have had a brief look at the XSD schemas, the next section provides an in-depth look at
schemas.
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>
15
Introduction to XML
04_596772 ch01.qxd 12/13/05 11:17 PM Page 15