Herong's Tutorial Notes On XML Technologies
Dr. Herong Yang, Version 3.04

XML Schema Definition (XSD)

This tutorial describes:

  • What is XML Schema Definition (XSD)
  • "Hello world!" Example of XSD
  • Validating XML Files Against XSD Files

What is XML Schema Definition (XSD)

XSD: A XML based language that defines validation rules for XML files. XSD stands for XML Schema Definition.

Main features of XSD:

  • XSD is an XML based language, meaning than XSD statements will be written in XML files.
  • XSD defines validation rules for XML files, meaning that XSD can be used to replace DTD, which is another language for defining XML validation rules.

"Hello world!" Example of XSD

Let's write our first XSD file to define the structure for our "Hello world!" XML file. Here is the XSD file, hello.xsd:

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <xsd:element name="p" type="xsd:string"/>
</xsd:schema>

The XSD file needs to be linked to the XML file, hello_xsd.xml:

<?xml version="1.0"?>
<p xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xsi:noNamespaceSchemaLocation="hello.xsd">
Hello world!</p>
Note that:
  • The XSD file is linked to the XML file through an attribute in the root element.

Validating XML Files Against XSD Files

Not all the XML file browsers support XSD validation. For example, Microsoft Internet Explorer 6.0 browse XML files every well as I mentioned in my previous notes, but I don't know how to make it to validate XML files against the linked XSD files.

XSD validation tools:

  • XML Spy 5.3
Dr. Herong Yang, updated in 2006
Herong's Tutorial Notes On XML Technologies - XML Schema Definition (XSD)