XML Schema Tutorial



XML Schema Basic


The root element of an XML Schema is a 'schema' element with the namespace 'http://www.w3.org/2001/XMLSchema'.


The 'schema' contains a root 'element' for the documents that XML Schema describes.


The 'element' contains its name and the structure of itself or its type.


XML schema example

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="item">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="id" type="xs:integer"/>
<xs:element name="type" type="xs:string"/>
<xs:element name="power" type="xs:integer"/>
</xs:sequence>
</xs:complexType>
</xs:element>

</xs:schema>


  • complexType : the element contains other elements as its children.
  • simpleType : the element doesn't contain any child elements.


XML example referencing an XML Schema

 <?xml version="1.0"?>

<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.elventek.com item.xsd">
<name>Wooden Sword</name>
<id>1010</id>
<type>weapon</type>
<power>10</power>
</item>