Content:
1. What isXMLDocument definition type
2. DTD Declaration
3.InternalDTD
4.ExternalDTD
5.DTDSyntax
1. What isXMLDocument definition type
The purpose of using XML is to exchange and share data. How can other users understand the structure of the XML document we created (including elements and attributes ), at this time, we need to develop a general method to describe the syntax rules of this XML document. Therefore, xml1.0 provides a mechanism-Document Type Definition (DTD), which is part of the Specification. It is similar that each product has a specific function specification, which can be simply understood as a DTD.
Finally, I thought of the HTML-defined tags, such as
2. DTD Declaration
The command in the XML document that uses the doctype Declaration to establish an association between XML and DTD. when reading the doctype command, it obtains the corresponding DTD and verifies the XML document according to the rules defined in the command.
Composition of DTD declarations: keywords, document root element names, optional external tokens, and optional tag declaration blocks.
(1) syntax structure:
<?XML version = "1.0" ecoding = "UTF-8"?>
<!Doctype stundents...>
<Students>
(2) Syntax Parsing:
AboveCodeUse "<! Doctype> "declares the tag. The first element (root element) of the document is students.
<! Doctype> there are two types of declaration Methods: Internal DTD declaration and external DTD declaration.
<! Doctype> the declaration must be placed after the XML declaration and before any document element. However, annotations and processing instructions can be inserted between the xml declaration and the doctype declaration.
3.InternalDTD
Use "<! Doctype [...]>" Statement.
(1) syntax structure:
<?XML version = "1.0" ecoding = "UTF-8"?>
<!Doctype element-name [
Element description
]>
<! -Document data zone -->
(2) Syntax Parsing:
<! Doctype: Specify the DTD. Note that doctype must be capitalized.
Element-Name: specify the name of the root element of this DTD. an XML file has only one root element.
Instance:
<? XML version = "1.0" encoding = "UTF-8" ?>
<! Doctype students [
<! Element students (student) + >
<! Element student (name, age, class) >
<! Element name (# pcdata) >
<! Element age (# pcdata) >
<! Element class (# pcdata) >
]>
< Students >
< Student >
< Name > Terrychan </ Name >
< Age > 22 </ Age >
< Class > 3 </ Class >
</ Student >
</ Students >
4.ExternalDTD
An external DTD is an independent XML document file. It is actually a text file, but uses. DTD as the file extension. External DTD can be referenced by multiple XML documents for easier operations.
(1) syntax structure:
<!Doctype type-of-Doc system/Public "DTD-name">
(2) Syntax Parsing:
<! Doctype: Specify the DTD.
Type-of-Doc: Specifies the document type name, which is defined by the user. It is usually consistent with the root element of the XML document using this DTD file.
System/public: only one of the two parameters can be selected. System refers to the use of private external DTD files, public refers to the call of public external DTD files.
DTD-name: the path and name for storing the DTD file
Therefore, the structure of the XML document that introduces the external DTD is as follows:
<?XML version = "1.0" ecoding = "UTF-8"?>
<!Doctype root element name system/Public "DTD file path and name">
<!-Document data zone -->
Instance
Students. DTD
XML version = "1.0" encoding = "UTF-8" ?>
doctype students [
>
element student (name, age, class) >
element name (# pcdata) >
element age (# pcdata) >
element class (# pcdata) >
]>
Students. xml
<? XML version = "1.0" encoding = "UTF-8" ?>
<! Doctype students system "students. DTD" >
< Students >
< Student >
< Name > Terrychan </ Name >
< Age > 22 </ Age >
< Class > 3</ Class >
</ Student >
</ Students >
5.DTDSyntax
A dtd contains the definition rules of elements, the definition rules of the relationship between elements, the available attributes of elements, and the available questions or symbol rules.
1. Element Declaration
(1) elements are the core of XML. They contain actual document information and indicate the logical structure of the information. Elements are arranged in a tree hierarchy and can be nested in other elements. Element names can be letters, numbers, or punctuation characters, such as colons, underscores, hyphens, and periods, but cannot start with a number, the first character can only be a character, underline, or colon.
(2) syntax structure:
<!Element element-name element-Definition>
(3) Syntax Parsing:
<! Element: Start Element settings. Note that the element must be capitalized.
Element-Name: name of the element to be set.
Element-Definition: the type of content between elements (<element> </element>.
(4) The content of element-definition elements in XML can be divided into any type, emptyl type, # pcdata type, parent element type, and hybrid element type.
A. Any Type
If you do not need to restrict the content of an element, you can use the any element type.
Syntax structure:
<!Element element-name any>
B. Empty type
The element has no content. It cannot contain child elements or text, but can have attributes.
Syntax structure:
<!Element element-name empty>
Instance:
<!Element student empty>
C. # pcdata type
The element can contain any character data, but cannot contain any child element.
Syntax structure:
<!Element element-Name (# pcdata)>
Instance:
<!Element name (# pcdata)>
D. Parent element type
The parent element type can only contain child elements without text. Use a regular expression to specify the sequence and number of occurrences of child elements.
Operation of tuples in Regular Expressions:
Symbol |
Meaning |
? |
Use "?" The modified element does not appear or only appears once. |
* |
Elements modified with "*" may not appear or appear multiple times |
+ |
Use "?" The modified element must appear at least once. |
Unsigned |
Elements without modifiers can only appear once |
() |
Used to Group Elements |
| |
You can only select one of the listed objects. |
, |
The listed objects must appear in the specified order. |
Instance:
Symbol |
Meaning |
(A | B | C) |
You can only select an appearance from A, B, and C. |
(A +) |
A must appear and can appear multiple times |
(B *) |
B does not appear. If B does, it may appear multiple times. |
(C ?) |
C can appear at most once. |
(A, B, C) |
A, B, and C must appear in order. |
(A + B + C), (D | E), F |
Divided into three groups |
E. Hybrid Element type
The Hybrid Element type is a mixture of child elements and text data.
Syntax structure:
<!Element element name (# pcdata | element-name1 | element-name2 | ...)>
Instance:
<!Element students (# pcdata | student )*>
2. Attribute Declaration
An attribute is a supplement and modification to an element. It can associate some simple features with the element. For example, in the HTML tag , SRC is an attribute. An element can have multiple attributes for modification.
Syntax structure:
<!ATTLIST element name
Attribute name attribute type Value Method
Attribute name attribute type Value Method
......
>
Attribute Value Method:
Value |
Description |
# Require |
Each instance of the element must contain this attribute. |
# Implied |
An instance of an element can selectively include this element. |
# Fixed value |
Fixed value attribute, which cannot be replaced by other values |
Default Value |
Default attribute defined in advance |
Property type:
Type |
Description |
Cdtat |
A plain text string consisting of Characters |
ID |
Define a unique identifier for an element in the document as a property value |
Idref |
The property value references the defined id value by using the ID of that element as the value of this attribute. |
Idrefs |
Idrefs is the plural form of idref. A value can contain multiple ID values separated by spaces. |
Entity |
The value is a defined entity. |
Entities |
This attribute value contains multiple external entity. Different entity values are separated by spaces. |
Nmtoken |
Indicates that the property value is a name that complies with the XML Naming rules. |
Nmtokens |
This attribute value contains multiple external nmtoken. Different nmtoken values are separated by spaces. |
Notation |
The value is a symbol declared in a DTD. This type is useful for data in non-XML format. |
3. Entity
Entity is pre-defined in XML, similarProgramYou can call the same object in multiple documents for convenient operations. There are two types of entities: pre-defined entities and custom entities.
(1) predefined entities
entity |
purpose |
& lt; |
generally used to replace characters smaller than signs (<) |
& gt; |
generally used to replace a character greater than the sign (>) |
& amp; |
generally used to replace characters (&) |
& quot; |
double quotation marks (") can be replaced. |
& apos; |
it can be used to replace single quotes (') in characters |
(2) custom object
Syntax structure:
<!Doctype rootname [
<! Entity entity-name "entity-content">
]>
Instance:
<!Doctype name [
<! Entity name "terrychan">
]>
Author: forevernome
Source: http://www.cnblogs.com/ForEvErNoME/
You are welcome to repost or share it, but be sure to declare it Article Source. If the article is helpful to you, I hope you can Recommendation Or Follow