XML Schema is a language for describing the structure of an XML document. The XML Schema specification is a recommendation of the W3C .
| XML Schema | |
|---|---|
| Standardization body | |
| Creator | |
| Created by | |
| Official site | |
Like most XML description languages, XML Schema was designed to define the rules that a document should obey. But, unlike other languages, XML Schema was designed so that it could be used in creating software for processing XML documents.
After checking the document for XML Schema compliance, the reader can create a document data model that includes:
- dictionary (names of elements and attributes);
- content model (relationships between elements and attributes and their structure);
- data types.
Each element in this model is associated with a specific data type, allowing you to build an object in memory that matches the structure of an XML document. It is much easier for object-oriented programming languages to deal with such an object than with a text file.
Another convenience of XML Schema is that one dictionary can refer to another, and thus, the developer can use existing dictionaries and it is easier to establish and distribute XML structure standards for certain tasks (for example, the SOAP protocol dictionary).
An XML Schema containing file usually has the extension “.xsd” ( X ML S chema d efinition).
Content
History
Version 1.0 was approved as a recommendation by the W3C consortium on May 2, 2001 . Thus, XML Schema became the first specification specification for XML document schema, which received the status of W3C recommendation, among many proposed for consideration. On October 28, 2004, the second edition of version 1.0 was published, correcting a number of errors.
On April 5, 2012, Version 1.1 was approved as a recommendation by the consortium.
Example
A simple example of an XML Schema located in the "country.xsd" file and describing the population of a country:
<? xml version = "1.0" encoding = "utf-8"?>
<xs: schema xmlns: xs = "http://www.w3.org/2001/XMLSchema" >
<xs: element name = "country" >
<xs: complexType>
<xs: sequence>
<xs: element name = "country_name" type = "xs: string" />
<xs: element name = "population" type = "xs: decimal" />
</ xs: sequence>
</ xs: complexType>
</ xs: element>
</ xs: schema>
An example of a document that matches this pattern:
<? xml version = "1.0" encoding = "utf-8"?>
<country>
<country_name> France </country_name>
<population> 59.7 </population>
</country>
See also
- DTD
- RELAX NG
- Schematron