Why use XML Schemas?
XML Schema is more powerful than DTD.
XML Schema supports data types
One of the most important capabilities of XML Schema is its support for data types.
With support for data types:
makes it easier to describe allowed document content
makes it easier to Verify data correctness
Make it easier to work with data from the database
Make it easier to define data constraints facets)
makes it easier to define data models (or data formats)
makes it easier to convert between different data types Data
Editor's note: Data constraints, or facets, is a term in the XML Schema prototype. It can be translated as "face" in Chinese and is used to constrain the allowed values of data types.
XML Schema uses XML syntax
Another important feature about XML Schema is that they are written in XML.
Writing XML Schema from XML has many benefits:
No need to learn a new language
You can use an XML editor to Edit the Schema file
You can use the XML parser to parse the Schema file
You can process the Schema through the XML DOM
Schema can be converted through XSLT
XML Schema can protect data communication
When data is sent from the sender to the recipient, The main point is that both parties should have the same "expectations" regarding the content.
Through XML Schema, the sender can describe the data in a way that the recipient can understand.
A type of data, such as "03-11-2004", is interpreted as November 3rd in some countries, but as March 11th in other countries.
But an XML element with a data type, such as: <date type="date">2004-03-11</date>, ensures a consistent understanding of the content, because XML The data type "date" requires the format "YYYY-MM-DD".
XML Schemas are extensible
XML Schemas are extensible because they are written in XML.
With extensible Schema definitions, you can:
Reuse your Schema in other Schemas
Create Your own data types derived from standard types
Referencing multiple Schema
well-formed is not enough
We call a document that conforms to XML syntax a well-formed XML document, such as:
It must start with an XML declaration
It must have a unique root element
The opening tag must match the closing tag
Elements are case sensitive
All elements must be closed
All elements must be properly nested
Must use entities for special characters
Even if documents are in good form, there is no guarantee that they will not contain errors, and these errors may have serious consequences.
Please consider the following scenario: You ordered 5 dozen laser printers, not 5 units. With XML Schema, most of these errors will be caught by your validation software.