Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

How to Use XML Schema

XSD How To?


An XML document can reference a DTD or an XML Schema.


A simple XML document:

Look at this XML document named "note.xml":

  Tove

  Jani

  Reminder

  Don't forget me this weekend!


The DTD File

The following example is the DTD file named "note.dtd", which defines the elements of the XML document above ("note.xml"):

Line 1 defines that the note element has four child elements: "to, from, heading, body".

Lines 2-5 define that the types of the to, from, heading, and body elements are "#PCDATA".


XML Schema

The following example is an XML Schema file named "note.xsd", which defines the elements of the XML document above ("note.xml"):

targetNamespace="http://www.w3schools.com"

xmlns="http://www.w3schools.com"

elementFormDefault="qualified">

  xs:complexType

    xs:sequence

     

     

     

     

   

 

The note element is a complex type because it contains other child elements. The other elements (to, from, heading, body) are simple types because they do not contain other elements. You will learn more about complex and simple types in the following chapters.


Reference to a DTD

This file contains a reference to a DTD:

  Tove

  Jani

  Reminder

  Don't forget me this weekend!


Reference to an XML Schema

This file contains a reference to an XML Schema:

xmlns="http://www.w3schools.com"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://www.w3schools.com note.xsd">

  Tove

  Jani

  Reminder

  Don't forget me this weekend!