You are on page 1of 4

Welcome to XML Schema School

XML Schema School


At XML Schema School, you will learn what an XML Schema is. You will also learn how XML Schema will replace
DTD, and how to use the XML Schema language in your applications. Start Learning XML Schema!
XML Schema References
At W3Schools you will find a list of valid XML Schema Elements. XML Schema Elements.
XML Schema Resources
A list of links to other valuable XML Schema Resources on the internet. XML Schema Resources.
Table of Contents
Introduction to XML Schemas
This introduction to the XML Schema language explains what an XML Schema is.
XML Schema Example
A simple example of a ship order, and a corresponding XML Schema.
XML Schema References
XML Schema Elements
A list of valid XML Schema Elements.
XML Schema Resources
XML Schema Resources on the Net
This is a list of links to other valuable XML Schema Resources on the Net.
Introduction to XML Schema
XML Schema is an XML based alternative to DTD.
An XML schema describes the structure of an XML document.
What You Should Already Know
Before you study the XML Schema Language, you should have a basic understanding of XML and XML Namespaces. If
you want to study these items first, please visit our XML School.
What is an XML Schema?
An XML Schema:
define elements that can appear in a document
define attributes that can appear in a document
define which elements are child elements
defines the sequence in which the child elements can appear
defines the number of child elements
defines whether an element is empty or can include text
define default values for attributes
The purpose of a Schema is to define the legal building blocks of an XML document, just like a DTD.
BUT....
XML Schemas are the Successors of DTDs
XML Schema was originally proposed by Microsoft, but is now a W3C proposed recommendation.
We think that very soon XML Schemas will be used in Web applications as a replacement for DTDs. Here are the reasons
why:
XML Schemas are easier to learn than DTD
XML Schemas are extensible to future additions
XML Schemas are richer and more useful than DTDs
XML Schemas are written in XML
XML Schemas support data types
XML Schemas support namespaces

XML Schema is a W3C Proposed Recommendation


Note that XML Schema is still a W3C Proposed Recommendation. A Proposed Recommendation is subject to changes, and
the specification will not be stable before it becomes a W3C Recommendation.
However - according to the W3C Working Group - substantial changes to the specification are not anticipated, and the
XML Schema specification is expected to reach a full Recommendation this year.
For a full overview of W3C Activities and Status, visit our W3C School.
An XML Schema Example
Example XML Shipping Order
Remember the CD catalog from XML School? This is a CD order:
<?xml version="1.0"?>
<shipOrder>
<shipTo>
<name>Tove Svendson</name>
<street>Ragnhildvei 2</street>
<address>4000 Stavanger</address>
<country>Norway</country>
</shipTo>
<items>
<item>
<title>Empire Burlesque</title>
<quantity>1</quantity>
<price>10.90</price>
</item>
<item>
<title>Hide your heart</title>
<quantity>1</quantity>
<price>9.90</price>
</item>
</items>
</shipOrder>
The order above consists of a root element <shipOrder>, with two child elements <shipTo> and <items>. The <items>
element contains <item> elements. An <item> element contains <title>,<quantity>, and <price> elements.
Example XML Schema
This is the XML Schema that defines the above order:
<xsd:schema xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<xsd:element name="shipOrder" type="order"/>
<xsd:complexType name="order">
<xsd:element name="shipTo" type="shipAddress"/>
<xsd:element name="items" type="cdItems"/>
</xsd:complexType>
<xsd:complexType name="shipAddress">
<xsd:element name="name"
type="xsd:string"/>
<xsd:element name="street" type="xsd:string"/>
<xsd:element name="address" type="xsd:string"/>
<xsd:element name="country" type="xsd:string"/>
</xsd:complexType>
<xsd:complexType name="cdItems">
<xsd:element name="item"
type="cdItem"/>
</xsd:complexType>
<xsd:complexType name="cdItem">
<xsd:element name="title" type="xsd:string"/>
<xsd:element name="quantity" type="xsd:positiveInteger"/> <xsd:element name="price"
</xsd:complexType>
</xsd:schema>

type="xsd:decimal"/>

The XML Schema above defines the element <shipOrder> to be of the type order. Order is a complex type element
consisting of the elements <shipTo> and <items>. The <shipTo> element is of the type shipAddress - a complex type
element consisting of the elements <name>, <street>, <address>, and <country>. The <items> element is of the type
cdItems - a complex type element consisting of <item> elements. The <item> element is of the type cdItem - a complex
type element consisting of <title>, <quantity>, and <price> elements. The <title> element is a normal element of the type
string.
Difficult? Read it once more. You will soon understand it.
If you have Internet Explorer 5.0 or higher, you can take a look at both the order and the schema.
XML Schema References
XML Schema elements
Element
Explanation
<all>
Specifies which child elements can be present. No specific order. The
elements are optional, but can only appear once
<annotation>
The parent element of the comment elements:
<appInfo> and <documentation>
<any>
Includes content from another Schema
<anyAttribute>
<appInfo>
A comment element. Provides a title to the Schema
<attribute>
<attributeGroup>
<choice>
Replaces the "|" operator in a DTD
<complexType> A set of attributes that declares the children of the specified element
<documentation>A comment element. Provides useful information about the Schema
<element>
Represents the specified element
<enumeration>
<field>
<group>
<import>
<include>
<key>
<keyref>
<length>
The length of the specified element
<maxInclusive>
<maxLength>
The specified element's value cannot be larger than the maxLength value
<minInclusive>
<minLength>
The specified element's value cannot be less than the minLength value
<pattern>
<schema>
The root element of the schema.
<selector>
<sequence>
Replaces the "," operator in a DTD
<simpleType>
<unique>

child

XML Schema Resources and Links


XML Schema Resources at W3C
From the W3C Working Drafts. 7. April 2000:
XML Schema Part 0 - A Primer.
This document is a description of the XML Schema language, oriented towards quickly understanding how to create XML
Schemas.
XML Schema Part 1 -Structures.
This document specifies the XML Schema definition language.
XML Schema Part 2 - Data types.
This document proposes facilities for defining data types to be used in XML Schemas and other XML specifications.

XML Schema Resources on the Web


Web Developers Virtual Library Schema Resource Section
WDVL's XML Schema Resources section is an extensive collection of schema-related specifications, articles,
presentations, software, and other schema sites.