Home >>XML Tutorial >XML Schema

XML Schema

XML Schema

What is XML schema

XML schema is a language used to describe XML documents constraints. There are too many scheme languages that are used for example Relax- NG and XSD (XML schema definition) for a few days now.

The structure of an XML document is specified with an XML schema. It is like DTD but offers more XML structure control.

Checking Validation

If an XML document includes the correct syntax, it is considered "well-formed." A well-formed, valid XML document is one validated against schema.

Visit http://www.xmlvalidation.com to validate the XML file against schema or DTD.

XML Schema Example

Let's create a schema file.


<?xml version="1.0"?>  
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"  
<xs:element name="employee">  
      <xs:element name="firstname" type="xs:string"/>  
      <xs:element name="lastname" type="xs:string"/>  
      <xs:element name="email" type="xs:string"/>  

Let's see the xml file using XML schema or XSD file.


<?xml version="1.0"?>  
xsi:schemaLocation="http://www.phptpoint.com employee.xsd">  
  <email>[email protected]</email>  

Description of XML Schema

<xs:element name="employee"> :It determines employee name of element.

<xs:complexType> : This determines that the 'employee' aspect is type complex.

<xs:sequence> :This determines that the form of complex is a sequence of elements.

<xs:element name="firstname" type="xs:string"/> :This determines the string / text type is the element 'firstname.'

<xs:element name="lastname" type="xs:string"/> :This determines the string / text sort is the element 'lastname.'

<xs:element name="email" type="xs:string"/> :This determines the string / text sort is the element 'email.'

XML Schema Data types

There are two types of data types in XML schema.

  1. simpleType
  2. complexType


The simpleType lets you have elements based on text. It has less features, less kid components and can not be left empty.


The complexType lets you keep multiple elements and attributes. This may contain more sub-elements and may be left empty.

No Sidebar ads