Schema is the definition and description of the structure of an XML document. It is mainly used to constrain the XML file and verify the validity of the XML file. The role of DTD is to define the legal construction module of XML. It uses a series of legal elements to define the document structure. The differences between them are as follows:
1. schema itself is also an XML document. The DTD definition has nothing to do with XML. schema has many advantages in understanding and practical application.
2. The structure of the DTD document is "tiled". If a complex XML document is defined, it is difficult to grasp the nested relationship between each element. The schema document has a strong structure, the nested relationship between elements is very intuitive.
3. The DTD can only specify that the element contains text, but cannot define the specific type of the element text, such as struct type, integer type, date type, and custom type. Schema is more powerful than DTD in this respect.
4. The schema supports the description of the order of element nodes. The DTD does not provide a description of unordered conditions. To define unordered conditions, all conditions that must be in an exhaustive arrangement must be defined. Schema can use Xs: all to indicate disorder.
5. namespace support. The DTD cannot use the namespace of XML, and the schema satisfies the namespace well. In addition, schema also provides two methods to reference namespaces: Include and import.