Home >Backend Development >XML/RSS Tutorial >Detailed explanation of DTD
##Basic overview
(Document Type Definition) is a set of grammatical rules about tags established for data exchange between programs. It is part of the Standard Generalized Markup Language (SGML) and Extensible Markup Language (XML) version 1.0, and is documented under Some DTD syntax rule verifies that the format conforms to this rule. Document type definitions can also be used to ensure the legality of standard universal markup language and extensible markup language document formats. You can compare documents with document type definition files to check whether the document conforms to the specification and whether the elements and tags are used correctly. File instances provide applications with a format for exchanging data.
PS: In short, DTD is used to constrain XML document, so that it can be used under certain specifications. In addition to DTD technology, there is also Schema technology, which is also used For constrained XML documents.
Reference document:DTD http://www.php.cn/
Reference document:Schema http://www.php.cn/
DTD
PS: Constrained by DTD, XML can be customized under the constraints of DTD, but DTD has A disadvantage is that it cannot impose range constraints such as numerical constraints on the data.
DTDDTDDocumentation
##d5896d8fab48258bc5208998b65f8a25External
DTDDocument
c9fe9a999289c144839afaf84993cb83Internal and external
DTDDocument combination
c49cc1bbed7f32fc382766a582d38140Note:
1
, definition keywords must be capitalized, for example:DOCTYPE, ELEMENT, ATTLIST. 2
,When the referenced file is local, the following method is used:
059c399813080446724273da8d03a65f
For example: 96e41340e472072b366436fa660bd81f
When the referenced file is a public file, the following method is used:
c16d7bbfd56d20e0a1ba120e2b9a44b5
##For example: f6b23a4dcfcf2a7ce51a065861e67dc3
DTD8a200477f44ef1072bb1d4a0c7920261
Explanation: ELEMENT: Keyword(must be capitalized).
NAME: Element name.
CONTENT: There are four element types, all of which must be capitalized.
1、EMPTY-This element cannot contain sub-elements and text, but it can have attributes (empty elements)
## 2、ANY-This element can contain anything in DTD## Element content defined in # 3
、#PCDATA-can contain any character data, but cannot It contains any sub-elements## 4, other types
(combination), can be a sub-element, a combination of sub-element and modifier, a combination of basic element, sub-element and modifier. Case:
3ceb8b302a752410845e00ddf5488f8126ed0e6047a1db75d76d12a6f7876de0< ;!ELEMENT Author
(#PCDATA)>ded3ccbb88539977f7ea6146fb2375b4
772d6896d7a6727c85d7ccfd9db439a3
8847d77a032f4f9263c9eeda19e6e8c1
Modifier
Use |
Example |
Example description |
|
( ) |
Used to group elements |
(古龙|Jin Yong|Liang Yusheng),(Wang Shuo|Yu Jie) |
Divided into two groups |
| | Select one of the listed objects |
(Men|Women) |
means that a man or a woman must appear, and you can only choose one |
##+ | The object appears at least once and can appear multiple times (1 or multiple times) |
(Member +) |
indicates that the member must appear, and multiple members can appear Member |
* | ##This object is allowed to appear zero to any number of times (0 to many times) | (Hobby* ) | Hobby can appear zero to multiple times|
This object can appear, But it can only appear once | (0 to 1 times) | (Rookie? ) ##The rookie can appear or not. If it appears, Can only appear once at most | |
Objects must appear in the specified order |
(Watermelon | ,
Apple,banana) ## means watermelon, apple, banana must appear, and appear in this order |
# # ##DTD AttributesBasic SyntaxExplanation: ATTLIST : attribute list, (must be capitalized ).Element name: The name of the corresponding element. Attribute: There can be multiple attributes, and the format is name type attribute property Type: ##PS : Commonly used ones areCDATA(Character type), enumeration (The enumeration format is (value1| Value2|Value3...)),ID(ID cannot be repeated and cannot start with a number ), IDREF( refers to another IDValue),IDREFS(can reference multiple ID Values, separated by spaces ) Attribute characteristics are:
Case: <!ELEMENT 班级 (学生+,作者)> <!ATTLIST 班级 班次 CDATA "1班" 编号 ID #REQUIRED > <!ELEMENT 学生 (名字,年龄,介绍)> <!ELEMENT 作者 (#PCDATA)> <!ATTLIST 学生 地址 CDATA #IMPLIED 授课方式 CDATA #FIXED "面授" 学号 ID #REQUIRED 班级编号 IDREF #REQUIRED 朋友 IDREFS #IMPLIED > <!ELEMENT 名字 (#PCDATA)> <!ELEMENT 年龄 (#PCDATA)> <!ELEMENT 介绍 (#PCDATA)> Entity XML, and parameter entities are generally used in DTD. Basic syntax ##30c188cd2a4b3e112bcbcf3f63ba1049 // Reference entity##dcb0500563c952f8097a4d6ee0799e77 // Parameter entityExplanation: 1, the reference entity can be referenced
|