Table of Contents
DTDDetailed explanation" >DTDDetailed explanation
" >Element
XML
##<!ENTITY
Home Backend Development XML/RSS Tutorial Detailed explanation of DTD

Detailed explanation of DTD

Feb 20, 2017 pm 03:06 PM

DTDDetailed explanation

##Basic overview


Document Type Definition

(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

Schematic

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.

DTD

Declaration and reference of document

Internal

DTDDocumentation

##Root element [Definition content]>External

DTD

Document

Root element SYSTEM "DTD File path">Internal and external

DTD

Document combination

Root element SYSTEM "DTDFile path" [

Definition content

]>Note:

1

, definition keywords must be capitalized, for example:

DOCTYPE, ELEMENT, ATTLIST. 2

,

When the referenced file is local, the following method is used:

Document root node SYSTEM "URL of the DTD file">

For example: Bookshelf SYSTEM book. dtd>

When the referenced file is a public file, the following method is used:

Document root node PUBLIC "DTDname" "DTDfileURL">

##For example: "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">

DTD

Element

Basic Grammar

Explanation:

ELEMENT: Keyword

(must be capitalized).

NAME

: Element name.

CONTENT

: There are four element types, all of which must be capitalized.

1EMPTY-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:

Class

(

Student+,Author)>Student

(

Name,Age,Introduction)>< ;!ELEMENT Author

(#PCDATA)>

Name

(#PCDATA)>

Age

(#PCDATA)>

Introduction

(#PCDATA)>

Modifier

Symbol##This object is allowed to appear zero to any number of times ( (HobbyHobby can appear zero to multiple times?This object can appear, But it can only appear once (Rookie,,

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

*

0

to many times)

*

)

(0

to 1 times)

?

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

Attributes

Basic Syntax


Element name

##Attribute name Type Attribute attribute

Attribute name Type Attribute characteristics......>

Explanation:

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 are

CDATA(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)>
Copy after login

Entity

There are two types of entities: reference entities and parameter entities. Reference entities are generally used in

XML

, and parameter entities are generally used in DTD. Basic syntax

##Entity name

"Entity content"> // Reference entity##Entity name

"Entity content" > // Parameter entityExplanation: 1, the reference entity can be referenced

DTD

XML file, use &entity name; to use entity content. 2. I don’t know if it’s because of my computer. You can’t use reference entities in external DTD

. If you use it, put the reference entity definition in In the internal DTD, it can be used. 3, parameter entity is used in DTD

, use %entity name;use

4、可以将那些重复使用的值定义成实体,这样能减少代码的冗余度。

5、在外部DTD中,引用实体最好放在DTD底部,参数实体最好放在DTD顶部。

案例:

<!ENTITY % sex "男|女">
<!ELEMENT 班级 (学生+,作者)>
<!ELEMENT 学生 (名字,年龄,介绍)>
<!ELEMENT 作者 (#PCDATA)>
<!ATTLIST 学生
	性别 (%sex;) #REQUIRED
>
<!ELEMENT 名字 (#PCDATA)>
<!ELEMENT 年龄 (#PCDATA)>
<!ELEMENT 介绍 (#PCDATA)>
<!ENTITY writer "Switch">
Copy after login


综合案例1

XML3.dtd

<!ENTITY % sex "男|女">
<!ELEMENT 班级 (学生+,作者)>
<!ATTLIST 班级
	班次 CDATA "1班"
	编号 ID #REQUIRED
>
<!ELEMENT 学生 (名字,年龄,介绍)>
<!ELEMENT 作者 (#PCDATA)>
<!ATTLIST 学生
	地址 CDATA #IMPLIED
	授课方式 CDATA #FIXED "面授"
	学号 ID #REQUIRED
	班级编号 IDREF #REQUIRED
	朋友 IDREFS #IMPLIED
	性别 (%sex;) #REQUIRED
>
<!ELEMENT 名字 (#PCDATA)>
<!ELEMENT 年龄 (#PCDATA)>
<!ELEMENT 介绍 (#PCDATA)>
Copy after login


XML3.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- 引入DTD -->
<!DOCTYPE 班级 SYSTEM "XML3.dtd"
[<!ENTITY writer "Switch">]>
<班级 编号="C1" 班次="1班">
	<学生  地址="湖南" 授课方式="面授" 学号="n1" 班级编号="C1" 朋友="n2" 性别="男">
		<名字>张三</名字>
		<年龄>20</年龄>
		<介绍>不错</介绍>
	</学生>
	<学生 授课方式="面授" 学号="n2" 班级编号="C1" 朋友="n1 n3" 性别="女">
		<名字>李四</名字>
		<年龄>18</年龄>
		<介绍>很好</介绍>
	</学生>
	<学生 授课方式="面授" 学号="n3" 班级编号="C1" 朋友="n2" 性别="男">
		<名字>王五</名字>
		<年龄>22</年龄>
		<介绍>非常好</介绍>
	</学生>
	<作者>&writer;</作者>
</班级>
Copy after login


综合案例2

XML4.dtd

<!ENTITY AUTHOR "John Doe">
<!ENTITY COMPANY "JD Power Tools, Inc.">
<!ENTITY EMAIL "jd@jd-tools.com">

<!ELEMENT CATALOG (PRODUCT+)>

<!ELEMENT PRODUCT
(SPECIFICATIONS+,OPTIONS?,PRICE+,NOTES?)>
<!ATTLIST PRODUCT
NAME CDATA #IMPLIED
CATEGORY (HandTool|Table|Shop-Professional) "HandTool"
PARTNUM CDATA #IMPLIED
PLANT (Pittsburgh|Milwaukee|Chicago) "Chicago"
INVENTORY (InStock|Backordered|Discontinued) "InStock">

<!ELEMENT SPECIFICATIONS (#PCDATA)>
<!ATTLIST SPECIFICATIONS
WEIGHT CDATA #IMPLIED
POWER CDATA #IMPLIED>

<!ELEMENT OPTIONS (#PCDATA)>
<!ATTLIST OPTIONS
FINISH (Metal|Polished|Matte) "Matte" 
ADAPTER (Included|Optional|NotApplicable) "Included"
CASE (HardShell|Soft|NotApplicable) "HardShell">

<!ELEMENT PRICE (#PCDATA)>
<!ATTLIST PRICE
MSRP CDATA #IMPLIED
WHOLESALE CDATA #IMPLIED
STREET CDATA #IMPLIED
SHIPPING CDATA #IMPLIED>

<!ELEMENT NOTES (#PCDATA)>
Copy after login


XML4.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE CATALOG SYSTEM "XML4.dtd">
<CATALOG>
	<PRODUCT NAME="C&#39;estbon" CATEGORY="Shop-Professional" INVENTORY="Backordered" PARTNUM="10" PLANT="Chicago">
		<SPECIFICATIONS POWER="0" WEIGHT="555ml">SPECIFICATIONS</SPECIFICATIONS>
		<OPTIONS>OPTIONS</OPTIONS>
		<PRICE>2</PRICE>
		<NOTES>NOTES</NOTES>
	</PRODUCT>
</CATALOG>
Copy after login

 以上就是DTD详解的内容,更多相关内容请关注PHP中文网(www.php.cn)!


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1655
14
PHP Tutorial
1252
29
C# Tutorial
1226
24
Securing Your XML/RSS Feeds: A Comprehensive Security Checklist Securing Your XML/RSS Feeds: A Comprehensive Security Checklist Apr 08, 2025 am 12:06 AM

Methods to ensure the security of XML/RSSfeeds include: 1. Data verification, 2. Encrypted transmission, 3. Access control, 4. Logs and monitoring. These measures protect the integrity and confidentiality of data through network security protocols, data encryption algorithms and access control mechanisms.

Advanced XML/RSS Tutorial: Ace Your Next Technical Interview Advanced XML/RSS Tutorial: Ace Your Next Technical Interview Apr 06, 2025 am 12:12 AM

XML is a markup language for data storage and exchange, and RSS is an XML-based format for publishing updated content. 1. XML defines data structures, suitable for data exchange and storage. 2.RSS is used for content subscription and uses special libraries when parsing. 3. When parsing XML, you can use DOM or SAX. When generating XML and RSS, elements and attributes must be set correctly.

RSS Document Tools: Building, Validating, and Publishing Feeds RSS Document Tools: Building, Validating, and Publishing Feeds Apr 09, 2025 am 12:10 AM

How to build, validate and publish RSSfeeds? 1. Build: Use Python scripts to generate RSSfeed, including title, link, description and release date. 2. Verification: Use FeedValidator.org or Python script to check whether RSSfeed complies with RSS2.0 standards. 3. Publish: Upload RSS files to the server, or use Flask to generate and publish RSSfeed dynamically. Through these steps, you can effectively manage and share content.

XML/RSS and REST APIs: Best Practices for Modern Web Development XML/RSS and REST APIs: Best Practices for Modern Web Development Apr 04, 2025 am 12:08 AM

XML/RSS and RESTAPI work together in modern network development by: 1) XML/RSS is used for content publishing and subscribing, and 2) RESTAPI is used for designing and operating network services. Using these two can achieve efficient content management and dynamic updates.

Is There an RSS Alternative Based on JSON? Is There an RSS Alternative Based on JSON? Apr 10, 2025 am 09:31 AM

JSONFeed is a JSON-based RSS alternative that has its advantages simplicity and ease of use. 1) JSONFeed uses JSON format, which is easy to generate and parse. 2) It supports dynamic generation and is suitable for modern web development. 3) Using JSONFeed can improve content management efficiency and user experience.

XML's Advantages in RSS: A Technical Deep Dive XML's Advantages in RSS: A Technical Deep Dive Apr 23, 2025 am 12:02 AM

XML has the advantages of structured data, scalability, cross-platform compatibility and parsing verification in RSS. 1) Structured data ensures consistency and reliability of content; 2) Scalability allows the addition of custom tags to suit content needs; 3) Cross-platform compatibility makes it work seamlessly on different devices; 4) Analytical and verification tools ensure the quality and integrity of the feed.

From XML to Readable Content: Demystifying RSS Feeds From XML to Readable Content: Demystifying RSS Feeds Apr 11, 2025 am 12:03 AM

RSSfeedsareXMLdocumentsusedforcontentaggregationanddistribution.Totransformthemintoreadablecontent:1)ParsetheXMLusinglibrarieslikefeedparserinPython.2)HandledifferentRSSversionsandpotentialparsingerrors.3)Transformthedataintouser-friendlyformatsliket

From XML/RSS to JSON: Modern Data Transformation Strategies From XML/RSS to JSON: Modern Data Transformation Strategies Apr 05, 2025 am 12:08 AM

Use Python to convert from XML/RSS to JSON. 1) parse source data, 2) extract fields, 3) convert to JSON, 4) output JSON. Use the xml.etree.ElementTree and feedparser libraries to parse XML/RSS, and use the json library to generate JSON data.

See all articles