Content Summary: XML schemas, like DTDs, are responsible for defining and describing the structure and content patterns of XML documents. It can define the relationships between elements and elements in an XML document, and you can define the data types of elements and attributes.
What is an XML Schema
XML schemas, like DTDs, are responsible for defining and describing the structure and content patterns of XML documents. It can define the relationships between elements and elements in an XML document, and you can define the data types of elements and attributes.
The XML schema itself is an XML document that conforms to the XML syntax structure. It can be parsed using a generic XML parser.
Why to use Schema
Why do we have schemas when we have previously used DTDs to define the structure and data types of an XML?
Because DTDs have a number of drawbacks:
1 The DTD is based on regular expressions, and the descriptive ability is limited;
2 DTD is not supported by data type, and has insufficient capability in most application environments;
3 the constraint definition of DTD is not enough to make the semantic restriction of XML instance documents more detailed;
4 The structure of the DTD is not enough, the cost of reuse is relatively high;
5 The DTD does not use XML as a descriptive tool, and the DTD is built and accessed without a standard programming interface and cannot be maintained in a standard programming manner.
XML Schemas are designed for the shortcomings of these DTDs, and the benefits of XML Schemas are:
1 XML Schema based on XML, no specialized syntax
2 XML can be parsed and processed like other XML files
3 XML schema supports a series of data types (int, float, Boolean, date, etc.)
4 XML Schema provides an extensible data model.
5 XML schema supports integrated namespaces
6 XML Schema supports attribute groups.
A simple XML Schema document
In this schema, an element is defined: quantity, its type is nonNegativeInteger (nonnegative integer), and xmlns is the namespace of the schema, which is described in the 3rd part above.
The following XML fragment is legal:
<quantity>5</quantity>