Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of DTD

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article will explain the example analysis of DTD for you in detail. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

Basic overview

Document type definition (Document Type Definition) is a set of syntax rules about markers established for the exchange of data between programs. It is part of the specification of Standard Universal markup language (SGML) and Extensible markup language (XML) version 1.0, and documents can verify that the format conforms to some DTD syntax rule. Document type definition can also be used to ensure the legitimacy of standard general markup language and extensible markup language document formats. By comparing document and document type definition files, you can check whether the document conforms to the specification and whether the elements and tags are used correctly. The file instance provides the application with a format for data exchange.

PS: in short, DTD is used to constrain XML documents so that they can be used under certain specifications. In addition to DTD technology, there is also Schema technology, which is also used to constrain XML documents.

DTD schematic diagram

PS: through the DTD constraint, XML can be customized under the constraint of DTD, but DTD has the disadvantage that it cannot apply range constraints such as numerical constraints to the data.

Declaration and reference of DTD document

Internal DTD document

External DTD document

Combination of internal and external DTD documents

Note:

1. Definition keywords must be capitalized, such as DOCTYPE, ELEMENT, ATTLIST.

2 、

When the referenced file is local, use the following ways:

For example:

When the referenced file is a public file, use the following ways:

For example:

Basic syntax of DTD elements

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 child elements and text, but can have attributes (empty elements)

2. ANY- this element can contain any element content defined in DTD

3. # PCDATA- can contain any character data, but it cannot contain any child elements

4. Other types (combinations), which can be child elements, combinations of child elements and modifiers, combinations of basic elements and child elements and modifiers.

Case study:

Modifier

Symbol

Use

Example

Example illustration

(.)

Used to group elements

(Gulong | Jin Yong | Liang Yusheng), (Wang Shuo | Yu Jie)

Divide into two groups

| |

Select one of the listed objects

(man | woman)

It means that a man or a woman must show up, and can only choose one.

+

The object appears at least once and can occur multiple times (1 or more times)

(member +)

Indicates that members must be present, and there can be multiple members

*

This object allows zero to any number of times (0 to many times)

(hobby *)

Hobbies can occur zero to many times.

?

The object can appear, but only once (0 to 1 time)

(rookie?)

Rookies may or may not appear, and if they do, they can only appear once at most.

Objects must appear in the specified order

(watermelons, apples, bananas)

It means that watermelons, apples and bananas must appear and appear in this order

Basic syntax of DTD attribute

Attribute name type attribute property

Attribute name type attribute property... ...

>

Explanation:

ATTLIST: list of attributes (must be capitalized).

Element name: the name of the corresponding element.

Attributes: there can be multiple attributes in the format of a name type attribute property

Type:

PS: commonly used are CDATA (character type), enumeration (enumeration format is (value 1 | value 2 | value 3.), ID (ID cannot be repeated and cannot start with a number), IDREF (reference to another ID value), IDREFS (multiple ID values can be referenced, separated by spaces)

Attribute properties are:

Case study:

Entity

There are two kinds of entities: reference entity and parameter entity. Reference entity is generally used in XML, and parameter entity is generally used in DTD.

Basic grammar

/ / reference entity

/ / Parameter entity

Explanation:

1. Reference entities can use & entity name; to use entity content in XML files that reference DTD.

2. I don't know if it's my computer. Reference entities cannot be used in external DTD. If you use to define reference entities in an internal DTD, you can use them.

3. Parameter entity is used in DTD, using% entity name; using

4. Those reused values can be defined as entities, which can reduce the redundancy of the code.

5. In the external DTD, the reference entity is best placed at the bottom of the DTD, and the parameter entity is best placed at the top of the DTD.

Case study:

Comprehensive case 1:

XML3.dtd

XML3.xml

Zhang San 20 is good Li Si 18 is very good Wang Wu 22 is very good & writer

Comprehensive case 2:

XML4.dtd

XML4.xml

This is the end of SPECIFICATIONS OPTIONS 2 NOTES's article on "sample Analysis of DTD". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report