Like DTD (DTD syntax Overview), XML Schema also restricts a type of XML documents and determines their structures, elements, attributes, and data types. And the elements used in the XML document, entities, element attributes, constraints on the relationship between elements and entities. XML Schema was first proposed by Microsoft and accepted by W3C as a standard. Unlike DTD, the XML schema file uses the XML syntax, which is designed for many similarities with DTD, but surpasses DTD in terms of functionality and scalability. The following are some differences between them:
1. XML schema is an XML document. Unlike DTD, XML schema has its own unique syntax. For developers, you don't need to understand either of the two syntaxes to write a well-formatted XML document. For the development of XML analyzer, XML schema is also an XML syntax, which makes implementation and support easier. XML Schema inherits the scalability of XML.
2. Define the data type. In a DTD file, data can only be declared as sub-elements of the string type or string type, such as pcdata, CDATA, and ID. In XML schema Programming Language Also rich data types, such as integer, floating point, Boolean, and date. The advantage is obvious. Program When using an integer data, if you use a DTD definition, you must convert it from the struct type to an integer type, while the XML schema can be directly defined as an integer type.
3. XML schema is an open model. See the following XML document: < Item >
< Name > TG/dt latte </ Name >
< Quantity > 1 </ Quantity >
< Price > 2.00 </ Price >
</ Item >
The following describes its DTD and Schema: DTD:
<! Element name (# pcdata) >
<! Element quantity (# pcdata) >
<! Element price (# pcdata) >
<! Element item (name, quantity, price) >
Schema:
< Elementtype Name = "Name" />
< Elementtype Name = "Quantity" DT: Type = "Int" /> >
< Elementtype Name = "Price" DT: Type = "Fixed.14.4" />
< Elementtype Name = "Item" Model = "Open" >
< Element Type = "Name" />
< Element Type = "Quantity" />
< Element Type = "Price" />
</ Elementtype >
Add a <myitem: Time> PDT </myitem: Time> element in the XML file:< Item Xmlns: myitm = "Urn: myitems" >
< Name > TG/dt latte </ Name >
< Quantity > 1 </ Quantity >
< Price > 2.00 </ Price >
< Myitem: Time > 10: 21 PDT </ Myitem: Time >
</ Item >
the above DTD will cause a verification error, but the schema will not.
4. namespace Integration. An XML document can only be described by one DTD document, but can be described by multiple XML Schema documents. The latter fully supports namespaces.
The following are W3C official XML Schema documents:
XML Schema part 0
XML Schema Part 1
XML Schema Part 2 To be continued ........ (XML Schema syntax overview)