Introduction to XML Schema

The definition of an XML document, which includes the XML tags and their interrelationships. Residing within the document itself, an XML schema may be used to verify the integrity of the content. XML schema can be treated as grammar that validates the XML document. Various recommendations for an XML schema were submitted to the W3C, and a standard was approved in May 2001 that included the ability to define data by type (date, integer, etc.).
XML Schema is a superset of DTD, which is the standard SGML schema. Unlike DTD, W3C XML Schemais written in XML syntax, which although more verbose than DTD, can be created with any XML tools. Since XML Schema is written in XML it is easy to learn, self explaning and flexible than DTD.
 
XML Schema Structure
 
 
Grammar based Schema language
 
A grammar-based schema specifies what elements may be used in an XML instance document, the order of the elements, the number of occurrences of each element, and the content and datatype of each element and attribute.
 
 
Assertion based Schema language
 
An assertion-based schema makes assertions about the relationships that must hold between the elements and attributes in an XML instance document.
 
 
What is XML Schemas?
 
XML Schema is an XML vocabulary for expressing your data’s business rules
 
 
Purpose of XML Schemas
 
1. Specify: the structure of instance documents “this element contains these elements, which contains these other elements, etc”
2. Specify the datatype of each element/attribute “this element shall hold an integer with the range 0 to 12,000” (DTDs don’t do too well with specifying datatypes like this)
3. Specify which elements are child elements  
4. Specify the order of child elements  
5. Specify the number of child elements  
6. Specify whether an element is empty or can include text  
7. WSpecify default and fixed values for elements and attributes