XML DTD is currently using the most widely used XML schema, XML Schema has become a formal recommendation standard for W3C and has a trend of an XML DTD. Then, from the technical point of view, XML Schema has those differences in XML DTD, and XML Schema has those advantages?
introduction
XML DTD (XML Document Type Definition) is the most widely used model used in XML technology in recent years. However, since XML DTD does not fully meet the requirements of XML automation processing, for example, the mutual coordination between applications can not be achieved, lack of sufficient description of document structure, attribute, data type, etc., W3C in 2001 In May, XML Schema is officially recommended for XML standard mode. Obviously, W3C wants to describe the mainstream of the language as an XML schema in XML Schema, and gradually replaces XML DTD. So what is the advantage of XML Schema and XML DTD? Does the XML DTD really disappear in the field of XML mode description?
XML Mode and XML Format XML mode refers to a language that describes factors such as XML structures, constraints, such as XML Schema, XML DTD, XDR, SOX, and more. The XML format is the format of the XML document itself. This article uses XML Schema to represent the XML Schema mode standard recommended by W3C, and "XML Mode" represents all XML schema description languages.
From the description language of the pattern, both XML Schema and XML DTD belong to the syntax mode. Unlike concept modes, the syntax mode can be used in different syntax when describing the same matter, such as when describing the relational mode, whether using XML Schema or XML DTD, can be used to describe relationship modes with an element. Columns.
The mode must be expressed in some format. XML Schema has a very obvious difference with the XML DTD format. XML Schema is actually an application of XML, that is, XML Schema's format is identical to XML format. And as a subset of SGML DTD, XML DTD has a format that is completely different from XML format. This difference will bring a lot of benefits to the use of XML Schema:
XML users do not need to re-learn in order to understand XML Schema, save time; because XML Schema itself is also an XML, so many XML editing tools, API development packs, XML syntax analyzer can be directly Apply to XML Schema without amending. As an application of XML, XML Schema has inherited XML's self-descriptive and scalability, which makes XML Schema more readability and flexibility. Since the format is completely in the same way, XML Schema can be stored together with the XML document as described in the same way as XML, in addition to the XML document it described, convenient to management. The consistency of XML Schema and XML format makes it possible to switch between applications that use XML for data exchange. XML has a very high legitimacy requirement, XML DTD's description of XML, often used as a foundation for verifying the legality of XML, but the legality of the XML DTD itself is lacking a good verification mechanism and must be independently processed. XML Schema is different, which has the same legitimacy verification mechanism with XML.
type of data
Perhaps, for many developers, XML Schema compared to the XML DTD is the most significant feature of its support for data types. This is entirely because the data type provided by XML DTD has only ten built-in data types such as CDATA, ENUMERATED, NMTOKEN, NMTOKENS. Such small data types are often unable to meet the needs of documentation and data exchange. XML Schema is different, and it has 30 types of data types such as long, int, short, double, etc., and the three yuan consisting of Value Space, Lexical Space and Facet. Group gain greater flexibility. However, the true flexibility of the XML Schema data type comes from its support for user-defined types. XML Schema provides two ways to implement the definition of data types. 1) SimpleType, i.e., on the basis of the data type built in XML Schema or other simple data type (SimpleType), which is built by XML Schema, or defines the simple data type (SimpleType), by Restriction, List or Union The way the new data type is defined.
For example: Definition of source code 1 Restriction mode
Definition of Source 2 List SimplePe>
Source 3 Union mode definition
2) Composite type definition (complexType), which provides a powerful complex data type definition mechanism that enables complex data types including structural descriptions. Below is an example in which the table structure in the relational pattern is defined in the complextype, which is equipped with table t_c_type (psign, count), where psign is a CHAR data type, and Count is Number data type. There is: Source 4 ComplexType definitions
Not only that, the XML Schema also allows the content of the element to take null value, which can expand the scope of the XML Schema to the data situation, and XML DTD is not powerful. E.g:
Source code 5 xml Schema element to take null value definition
Element order Support XML DTD and XML Schema supports a description of sub-element node sequence, but XML DTD does not provide a description of disordered conditions, that is, if the elements are described in the XML DTD, it must be poor This method is not only cumbersome, but sometimes even unrealistic. For example, for Table A, B sub-elements, if they want them to appear in any order, use XML DTD to describe:
Source 6 A, B Chub Elements Announced XML DTD Definitions XML Version = "1.0" Encoding = "UTF-8"?> XML Schema provides
Source 7 a, B child elements Ante XML Schema definition
It can be seen that the disorderly description of sub-elements is simple to implement with XML Schema.
The purpose of named the namespace in XML is to be able to use some of the commonly defined definitions in other XML documents in an XML document (usually some elements or data types, etc.), and ensure that no semantics are generated conflict. XML DTD does not support this feature, which further limits the scope of application of XML DTD. And XML Schema is very good to meet this.
Moreover, XML Schema also provides two methods of incordude and import reference namespaces. In the following example, the XML Schema document references the other two XML Schema definitions, and the use of different namespaces by using Import. The keyref constraint between elements in different namespaces is also defined.
Source code 8 XML Schema using schema targetnamespace = "http://202.117.84.144" http://202.117.84.144 "http://202.117.84.144" xmlns = "http://www.w3.org/2001/xmlschema "xmlns: a =" http://202.117.84.228/middlewareSqlServer2000sqlservertest20211784228 "xmlns: b =" http://202.117.84.228/middlewareOracle805ioracletest20211784144 "elementFormDefault =" qualified ">
For the API support, the DOM and SAX may be the most commonly used XML API for technicians when you master and use XML technology. DOM and SAX are only valid for the XML instance document, although they can authenticate the XML document with XML DTD, but DOM and SAX have not provided the ability to parse the XML DTD document content, that is, we can't get DTD through DOM or SAX. Description of the declaration and constraints of the element, attribute. However, during the data exchange process based on XML DTD, some applications need to obtain the description of the DTD itself, to facilitate the processing of data in the XML document, such as how to use the relational data set XML documentation Map the XML DTD is a problem description in the relational mode. In order to achieve interpretation of XML DTD, the researchers must develop new interfaces or special tools for XML DTD, bringing great inconvenience. Since XML Schema itself is an XML document, we can easily parse XML Schema by using XML APIs such as DOM, SAX or JDOM, which implements the consistency of XML documents and its description mode processing mode, facilitating data transmission and exchange .
More clear attributes have restrictions, as well as the default values and enumeration XML DTDs to specify whether attributes appear in keywords # implied, # fixed, and #required, and support definitions of attribute default values. XML Schema provides a clearer tag to achieve clear and easy-to-understand. XML Schema discards the xml DTD #implied, no longer supports the implicit state of the property, and the statement must be given a clear state, and the property is displayed in prohiBITED. For the default expression, it is more intuitive, and it is given directly with Default.
Source 9 XML DTD, XML Schema restriction from happening attribute
For XML Schema's improvements in enumeration, see "XML problem # 7 W3C XML Schema and Document Type Definition (DTD) comparison" in References (Document 9).
Note XML DTD and XML Schema support This is a more flexible and useful comment: Documentation and AppInfo are available in XML Schema. They provide annotations for readers and applications.
Source 10 XML Schema Note
One conclusion is compared, it can be seen that XML Schema has stronger expressiveness than XML DTD, which can better meet the needs of different fields. So, is it possible to say that XML DTD will be replaced by XML Schema and eventually disappear. From the author's point of view, although XML Schema has a trend of an XML DTD in most applications, XML DTD still has its scope of application, and it is impossible to be completely replaced by XML Schema:
XML DTD is published as part of the XML standard, and W3C does not seem to be abolished from the XML standard, and support for XML DTD will continue. At present, most of the XML applications have made XML DTDs, and XML DTD tools are relatively mature. Under normal circumstances, these applications and tools do not choose to replace XML DTD in XML Schema. Upgrade, more choices should be supported. Of course, for those requirements for data exchange or description, XML DTD does not meet the application of functional requirements, with XML Schema instead of XML DTD has become an inevitable trend. Most algorithms related to the XML mode are based on XML DTD expansion. As a continuation of research, it will not discard the research results of XML DTD, but research on XML Schema will become a new hotspot. In some relatively simple processing environments, XML DTD will still have its one. Like other technologies, due to the emergence of new standards, XML DTD will gradually weaken, but the hierarchical database is still in use today, whether the XML Schema will completely replace XML DTD to make a conclusion seems to be too early.
Therefore, as a powerful standard, XML Schema is a trend as the mainstream of XML mode; but as a simplest XML mode, XML DTD will also play a role in a period of time.