XML Getting Started File Format Definition (DTD)

xiaoxiao2021-03-06  117

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: ... , 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: Zhang 3 Just choose one child element. In our XML file, it may also include a lot of "empty elements", ie: the element is alone, no end tags. Then, in the DTD, it is declared with the EMPTY keyword. Such as: . In the XML file, the null element does not need to end the mark, but must be written in This kind of way. In DTD, you can also declare something called Entity, let DTD and XML files are used. We can think of entity as a constant, it has a certain value. In DTD, Entity's declaration syntax is: . For example: We declare can write "ELEMENT author && Pc;". When references Entity, you must add "&&" symbol before the Entity name, and then add ";" symbol. In Example 1, the This sentence is the properties of the setting element, and the syntax for element properties set is: . Among them,

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: Zhang 3 Li Fudi Note: The value of the "Number" property is repeated, so error message will occur during the parsing process. This property settings in the settings of the property are #REquired, indicating that this property must appear in the tag of the XML file, otherwise the resolution will have an error. This property setting is the "Phone Number" setting a property named "Country Code", which is a general text. This property cannot be set in the tag, because this property is set to a attribute (#fix keyword) with a fixed value, the parser will automatically add this attribute and value "86" to the Mark. Table 2 Attribute Value Category Description CDATA property value is just a general text. ENUMERATED Lists the value range of this property, and only one attribute value can give attributes at a time. NMToken indicates that the attribute value can only be composed of letters, numbers, underscores,.,:, - these symbols. NMTOKENS indicates that the attribute value can be composed of multiple NMToken, and each NMToken is separated from spaces. ID This property is unique in the XML file, often used to represent a person's ID number. IDREF indicates that the value is referring to another ID attribute. iDREFS indicates that the value is referring to multiple ID properties, which are separated by spaces with spaces. Entity indicates that the setting value of this property is an external entity, such as a picture file. Entities This property contains multiple external Entity, separated from spaces between different Entity. The Notation property value is NOTATION declared in the DTD (what application is used to interpret some binary files, such as a picture). In the XML specification, two kernel properties are also specified, namely: XML: Space and XML: Lang, the internal identity name is start with XML: start, and your own defined attribute name cannot be in XML: start, otherwise parsing An error will occur. We have already talked in front of it, and the blank grid has a meaning in the XML file. The XML: Space property is to set the parser to pass the blanks in the XML file to the application after the application. XML: Space is an enumerated type attribute that can only be valued between default and preserve. XML: Space = "defaule" indicates that the parser passes the blank gyzym to the application, and the application has been configured by the application. If the XML: Space property is not set, the parser will use default by default to set this property.

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. 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

... 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: < ! Element name (#pcdata)> ]> XML Getting Started精 解 20.00 XML syntax 李 四 18.00

转载请注明原文地址:https://www.9cbs.com/read-98903.html

New Post(0)