The DTD can actually be considered as a template for one or more XML files, the elements in these XML files, the elements of the elements, the elements, the contents of the elements, and the contents of the elements, etc., must comply with the definitions in the DTD. The elements in the XML file are created based on the actual situation we have created. It is very difficult to create a high integrity, and the adaptive DTD is very difficult, because all industries have their own characteristics, so DTD is usually the scope defined in some application field, such as medical, architecture , Business, administration. The more the elements defined by the DTD is wide, the more complex it. The DTD can be a fully independent file or it can be set directly in the XML file. Therefore, the DTD is divided into external DTD (two DTDs that have been called another edited in the XML file) and the internal DTD (DTD directly in the XML file). For example, dozens of companies, partnership companies, vendors, and exchange electronic documents are using XML documents. Then we can put the DTD of these XML documents in a place, so that all the exchanged XML documents use this DTD, which is the most convenient practice, and also apply to the XML file in the company. The internal DTD internal DTD is defined in the file preambproduction area of the XML file. Grammar: : Define the XML file using the element in the [] tag, and then use> end DTD definitions. Below, let's take a look at how to define DTDs to the XML file. See Example 1. The DTD definition area in Example 1 can be regarded as a probably a DTD definition, defining the DTD, structure, and Example 1 DTD of the other XML files, but may need to add, delete or change something. In the middle of the DTD definition, it is an element setting. This is the most important part of the DTD. Its primary grammar is as follows: ... element>, which is other element or a general text. In Example 1, you can see, This element setting is to declare the "Reference" element, and it is the parent element of this element of "book". This element setting declares the "book" element, and it is the parent element of the three elements of "name", "author", "price". And the element settings declares the "Name" element, but this element only contains general characters, which is defined by the #pcdata keyword. In element settings, if the elements contain multiple child elements, such as: This "name", "author", "price" these tags The order in which the above is arranged in the XML file, each marker must be and only once.
If the element is set, according to , it can contain any set of elements in the element, and the number of occurrences and the order of the appearance is not limited, and in this element, in addition to the group Other elements, it is also possible to contain general characters. Sometimes, in the XML file, a tag may appear multiple times (or do not appear), then we can control tags in the side of the element in addition to the ANY keywords in their parent elements. The number of times occurred. These symbols are shown in Table 1. Table 1 number of symbols represent the number of tags? Do not appear or only one * does not appear or can have multiple times must have a symbol, such as: This element is set, "Books" tag can no or multiple times in the XML file; the "newspaper" mark must have more than one; the "magazine" tag can not appear or only once; and the "website" mark must appear and can only appear once. In a statement of some parent elements, it is possible that the child elements contain are used in multiple child elements, then we declare this parent element, you can declare it into selective elements, for example: . The selection of child elements are separated by "|", so we can write this in the XML file: Let's take a few examples to see how many commonly used elements properties are set. Example: This elementality setting is the "Name" element setting a property named "gender", this property of the properties value category is ENUMERATED, value The range is "male" or "female" (with "|" separate). If you don't assign a value for this attribute in an XML file, you will be "male" because the property internal value is a string "male". This property setting is a "Name" element to set an attribute called "Number". The property value category is ID, which means that the value is assigned to this attribute in the XML file. In this XML file, it is unique. If the following XML statement appears in the same XML file: XML: Space = "preserve" is that after the resolver passes the blank gyroids to the application, requiring the application to retain these spaces. XML: LANG attribute is used to set text information in the tag that is used in which language is used. The ISO-639 specifies the representative abbreviations of different languages, such as xml: lang = "en" represents English; XML: lang = "la" means Latin; XML: lang = "en" represents Chinese data; XML: lang = "zh-CN" Represents Chinese (Simplified); XML: lang = "zh-TW" Represents Chinese (Traditional). The system is fixed is XML: lang = "en", that is, the text information in the middle of the mark is in English. The external DTD external DTD is a file independent of the XML file. It is actually a text file, just use .dtd as the file extension. Because the external DTD is independent of the XML file, it can be used by multiple XML files, just like the same template can write out multiple different content files, this multiple XML files because they are referenced to the same external DTD, so they The structure is substantially the same. The external DTD is created, the syntax and internal DTD are the same, and the example of the internal DTD of Example 1 is written with an external DTD, and the files are as follows. The file is saved as a file named .dtd. XML Version = "1.0" encoding = "GB2312"?> In addition to the or to reference the created external DTD file. Table 3 Property Introduction Description #Required indicates that this property must appear in the tag. This property may not appear in the #implied tag. The value of the #fix attribute is a fixed value. Such a string is the value of this property in the string tag. This statement must be in the XML file file preface area, where
XML Version = "1.0" encoding = "gb2312"?> ... Schema Introduction The syntax of DTD is quite complex, and it does not meet the standard of XML files, self-contained. The above introduction is just a profile, the purpose is to help everyone can read the DTD file and create a simple DTD file when necessary, because now a lot of XML applications are built on DTD. In addition, one instead of DTD is the Schema defined by W3C, and Schema relative to DTD is the XML Schema document itself is also an XML document, rather than using a self-contained syntax like DTD. This makes it easy for users and developers because you can use the same tool to process XML Schema and other XML information, without having to specifically use special tools for Schema. Schema is easy to understand, knowing that XML syntax, people who rules can immediately understand it. The concept of Schema has been proposed, but the standard of W3C has recently come out, and the corresponding application support has not yet been perfect, but SCHEMA has become a trend of XML development. Example 1 DTD Definition Zone: XML Version = "1.0" Encoding = "GB2312"?> < ! Element name (#pcdata)> ]>