Validating XML Document using XML Schema-1

Estudies4you
Validating XML Document using XML Schema
Validating XML Document using XML Schema
XML Schema is an XML-based alternative to DTDs.
An XML Schema describes the structure of an XML document.
The XML Schema language is also referred to as XML Schema Definition (XSD).
The purpose of an XML Schema is to define the legal building blocks of an XML document, just like a DTD.

An XML Schema:
  • defines elements that can appear in a document
  • defines attributes that can appear in a document
  • defines which elements are child elements
  • defines the order of child elements
  • defines the number of child elements
  • defines whether an element is empty or can include text
  • defines data types for elements and attributes
  • defines default and fixed values for elements and attributes
XML Schemas are the Successors of DTDs
Many consider that very soon XML Schemas will be used in most Web applications as a replacement for DTDs.
Here are some reasons:
  • XML Schemas are extensible to future additions
  • XML Schemas are richer and more powerful than DTDs
  • XML Schemas are written in XML
  • XML Schemas support data types - XML Schemas support namespaces
XML Schemas Support Data Types
XML Schemas are much more powerful than DTDs.
One of the greatest strength of XML Schemas is the support for data types.
With support for data types, it is easier to:
  • Describe allowable document content
  • Validate the correctness of data
  • Work with data from a database
  • Define data patterns (data formats)
  • Convert data between different data types
XML Schemas use XML Syntax
Another great strength about XML Schemas is that they are written in XML.
Some benefits of that XML Schemas are written in XML:
  • You don't have to learn a new language
  • You can use your XML editor to edit your Schema files
  • You can use your XML parser to parse your Schema files
  • You can manipulate your Schema with the XML DOM
  • You can transform your Schema with XSLT
XML Schemas Secure Data Communication
When sending data from a sender to a receiver, it is essential that both parts have the same "expectations" about the content.
With XML Schemas, the sender can describe the data in a way that the receiver will understand.
For example:
A date like: "03-11-2004" will, in some countries, be interpreted as 3.November and in other countries as 11.March.
However, an XML element with a data type like <date type="date">2004-03-11</date>
ensures a mutual understanding of the content, because the XML data type "date" requires the format "YYYY-MM-DD".

XML Schemas are Extensible
XML Schemas are extensible, because they are written in XML.
With an extensible Schema definition you can:
  • Reuse your Schema in other Schemas
  • Create your own data types derived from the standard types
  • Reference multiple schemas in the same document
Sample XML, DTD and XML Schema
Here you will xml file, its corresponding dtd file and schema file.

Continue in next post
To Top