Recent Posts

Monday, 18 December 2017

XML Schemas

     An XML Schema describes the structure of an XML document. The XML Schema language is also referred to as XML Schema Definition (XSD).

What is an XSD?
1. XSD stands for XML Schema Definition
2. An XML schema is used to define the structure of an XML document.
3. Schemas are successors to DTDs.
4. Schemas are another approch used by the XML parser to validate an XML document.
5. It is a text file with .xsd extension

What XSD defines?
1. Defines elements that can appear in a document.
2. Defines attributes that can appear in a document.
3. Defines the number of child elements and their sequence.
4. Defines whether an element is empty or can include text.
5. Defines data types for elements and attributes.
6. Defines default and fixed values for elements and attributes.

Why Use XML Schemas?
XML Schemas Support Data Types
1. One of the greatest strength of XML Schema is the support for data types.
2. With support for data types:
  • It is easier to describe allowable document content.
  • It is easier to validate the correctness of data
  • It is easier to work with data from a database
  • It is easier to define data facets(restrictions on data)
  • It is easier to define data patterns(Data formats)
  • It is easier to convert data between different data types  
DTDs vs XSDs

XML Schema Structure
 A simple XML document
<?xml version=”1.0”>
   <body>Don't forget me this weekend!</body>

The XML Schema for the above example 
<?xml version="1.0"?>
<xs:schema xmlns:xs="" 
<xs:element name="email">
   <xs:element name="to" type="xs:string"/>
   <xs:element name="from" type="xs:string"/>
   <xs:element name="subject"  type="xs:string"/>
   <xs:element name="body" type="xs:string"/>

Main XML Schema Data types
General Data Types

Types representing Dates and Times


DTD-compatible Types


XML Schemas Data Types
     One of the greatest strength of XML Schemas is the support for data type. An XSD comprises of two kinds of data types.
1.Simple Type
2.Complex Type