XMLSchema can also be referenced as XSD (XMLSchemaDefinition. Basic knowledge you shall possess
XML Schema is an XML-based DTD substitution.
XML Schema describes the structure of an XML document.
The XML Schema language can also be referenced as XSD (XML Schema Definition.
Basic knowledge you shall possess
Before continuing to learn, you need to have a basic understanding of the following knowledge:
If you want to learn about these projects, visit these tutorials on the homepage.
What is XML Schema?
The role of XML Schema is to define the legal building module of XML documents, similar to DTD.
XML Schema:
Define elements that can be displayed in the document
Define attributes that can be displayed in the document
Define which element is a child element
Define the sequence of child elements
Number of defined child elements
Define whether the element is empty or whether it can contain text
Define the data types of elements and attributes
Define default values and fixed values of elements and attributes
XML Schema is the successor of DTD
We think that the XML Schema will soon replace the DTD in most network applications.
The reasons are as follows:
XML Schema can be expanded to meet future needs.
Improved XML Schema and more powerful functions
Write XML Schema based on XML
XML Schema supports data types
XML Schema supports namespaces
Why is XML Schema used?
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.
Support for data types:
Allows you to easily describe the content of a document.
Data correctness can be verified more easily
It is easier to work with data from databases.
Data facets)
It is easier to define data models (or data formats)
It is easier to convert data between different data types.
Editor's note: A data constraint, or facets, is a term in the XML Schema prototype. it can be translated into "planes" to constrain the allowed values of data types.
XML Schema uses XML syntax
Another important feature of XML Schema is that they are written in XML.
Writing XML Schema by XML has many advantages:
No need to learn new languages
You can use the XML editor to edit the Schema file.
You can use an XML parser to parse Schema files.
You can use xml dom to process Schema
You can use XSLT to convert the Schema.
XML Schema protects data communication
When data is sent from the sender to the receiver, the main point is that both parties should have the same "expectation" on the content ".
Through XML Schema, the sender can describe the data in a way that the receiver can understand.
A type of data, such as "03-11-2004", is interpreted as January 1, November 3 in some countries and considered as January 1, March 11 in other countries.
But an XML element with a data type, such: 2004-03-11 To ensure a consistent understanding of the content, because the XML data type "date" requires the format of "YYYY-MM-DD ".
Scalable XML Schema
XML Schema is extensible because it is written in XML.
With an extensible Schema definition, you can:
Use your Schema again in other schemas
Create your own data types derived from standard types
Reference multiple schemas in the same document
Good form is not enough
We call documents that conform to the XML syntax a well-formed XML document, for example:
It must start with an XML declaration
It must have a unique root element
The start tag must match the end tag.
The element is case sensitive.
All elements must be disabled.
All elements must be correctly nested.
Must use entity for special characters
Even if the document format is good, it cannot be guaranteed that they do not contain errors, and these errors may cause serious consequences.
Consider the following situation: you ordered five laser printers instead of five. Through XML Schema, most of these errors will be captured by your verification software.
How to use XML Schema
The XML document can reference DTD or XML Schema.
A simple XML document:
Please refer to the xml document named "note. XML:
George
John
Reminder
Don't forget the meeting!
DTD file
The following example shows the dtd file named "note. DTD", which defines the elements of the above XML document:
Line 3 defines four sub-elements: "to, from, heading, body ".
Rows 2nd-5 define the type of the to, from, heading, and body elements as "# PCDATA ".
XML Schema
The following example is an XML Schema file named "note. xsd", which defines the elements of the above XML document:
The note element is a composite type because it contains other child elements. Other elements (to, from, heading, body) are simple types because they do not contain other elements. You will learn more about composite and simple types in the following sections.
Reference to DTD
This file contains reference to DTD:
George
John
Reminder
Don't forget the meeting!
References to XML Schema
This file contains references to the XML Schema:
George
John
Reminder
Don't forget the meeting!
The above is the content of crazy XML learning Notes (7) ----------- XML Schema. For more information, see PHP Chinese website (www.php1.cn )!