Why useXML Schemas?
XML Schema is more powerful than DTD.
XML Schema Supports Data Types
One of the most important capabilities of XML Schema is support for data types.
Through the support of data types:
- Easier to describe allowed document content
- Easier to verify the correctness of data
- Easier to work with data from databases
- Easier to define data constraints (data facets)
- Easier to define data models (or data formats)
- Easier to convert data between different data types
Editor's note:Data constraints, also known as facets, are a term in the XML Schema specification, which can be translated as "face" in Chinese, and are used to constrain the allowable values of a data type.
XML Schema Uses XML Syntax
Another important feature of XML Schema is that they are written in XML.
There are many benefits to writing XML Schema in XML:
- No need to learn a new language
- You can use an XML editor to edit Schema files
- You can use an XML parser to parse Schema files
- You can process Schema through XML DOM
- You can transform Schema with XSLT
XML Schema Protects Data Communication
When data is sent from a sender to a receiver, the point is that both parties should have the same "expectations" about the content.
Through XML Schema, the sender can describe data in a way that the receiver can understand.
A piece of data, such as "03-11-2004", is interpreted as November 3rd in some countries, and as March 11th in others.
But an XML element with a data type, such as: <date type="date">2004-03-11</date>, can ensure consistent understanding of the content, because the XML data type "date" requires the format "YYYY-MM-DD".
XML Schema is Extensible
XML Schema is extensible because it is written in XML.
With an extensible Schema definition, you can:
- Reuse your Schema in other Schemas
- Create your own data types derived from standard types
- Reference multiple Schemas in the same document
Well-formed is not enough
We call documents that conform to XML syntax well-formed XML documents, such as:
- It must start with an XML declaration
- It must have a unique root element
- Start tags must match end tags
- Elements are case-sensitive
- All elements must be closed
- All elements must be properly nested
- Entities must be used for special characters
Even if documents are well-formed, it still cannot be guaranteed that they do not contain errors, and these errors may have serious consequences.
Consider the following situation: you ordered 5 dozen laser printers, not 5 units. Through XML Schema, most such errors will be caught by your validation software.
Other Extensions