惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Secure Thoughts
罗磊的独立博客
T
The Blog of Author Tim Ferriss
人人都是产品经理
人人都是产品经理
博客园 - 叶小钗
Last Week in AI
Last Week in AI
美团技术团队
Google Online Security Blog
Google Online Security Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
D
Docker
G
Google Developers Blog
大猫的无限游戏
大猫的无限游戏
酷 壳 – CoolShell
酷 壳 – CoolShell
小众软件
小众软件
月光博客
月光博客
L
LINUX DO - 最新话题
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
W
WeLiveSecurity
H
Heimdal Security Blog
Vercel News
Vercel News
SecWiki News
SecWiki News
Forbes - Security
Forbes - Security
Blog — PlanetScale
Blog — PlanetScale
Google DeepMind News
Google DeepMind News
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
www.infosecurity-magazine.com
www.infosecurity-magazine.com
TaoSecurity Blog
TaoSecurity Blog
T
Troy Hunt's Blog
A
About on SuperTechFans
C
Check Point Blog
S
Security Affairs
Hacker News - Newest:
Hacker News - Newest: "LLM"
AI
AI
WordPress大学
WordPress大学
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Help Net Security
Help Net Security
博客园_首页
The Last Watchdog
The Last Watchdog
S
SegmentFault 最新的问题
Hugging Face - Blog
Hugging Face - Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
Engineering at Meta
Engineering at Meta
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
I
Intezer
K
Kaspersky official blog
M
MIT News - Artificial intelligence
J
Java Code Geeks
G
GRAHAM CLULEY
P
Palo Alto Networks Blog

博客园 - Sady

Start my new level SCM Chart How to read the contents of a remote web page rs.open syntax Deal with replacing a string in an NTEXT field Get random records How to debug a vb dll for asp SQL Value Example ASP Class javascript injection attack - Sady 封装ASP Version 3 of OA System The relation chart of Supply Chain Management Version 2 of our oa system Supply Chain Management on Website Away for so long Self-promotion CSharp中几个关键概念 类的继承
DTD
Sady · 2007-12-11 · via 博客园 - Sady

A Document Type Definition (DTD) defines the legal building blocks of an XML document. It defines the document structure with a list of legal elements and attributes.
<!DOCTYPE root-element [element-declarations]>
Example XML document with an internal DTD:

<?xml version="1.0"?>
<!DOCTYPE note [
  <!ELEMENT note (to,from,heading,body)
>
  
<!ELEMENT to      (#PCDATA)>
  
<!ELEMENT from    (#PCDATA)>
  
<!ELEMENT heading (#PCDATA)>
  
<!ELEMENT body    (#PCDATA)>
]>
<note>
  
<to>Tove</to>
  
<from>Jani</from>
  
<heading>Reminder</heading>
  
<body>Don't forget me this weekend</body>
</note> 

Or with an internal DTD:

<!DOCTYPE note SYSTEM "note.dtd">

The DTD above is interpreted like this:
!DOCTYPE note defines that the root element of this document is note.
!ELEMENT note defines that the note element contains four elements: "to,from,heading,body".
!ELEMENT to defines the to element  to be of the type "#PCDATA".
!ELEMENT from defines the from element to be of the type "#PCDATA".
!ELEMENT heading defines the heading element to be of the type "#PCDATA".
!ELEMENT body defines the body element to be of the type "#PCDATA".

PCDATA is text that WILL be parsed by a parser. The text will be examined by the parser for entities and markup.
CDATA is text that will NOT be parsed by a parser
Declaring Elements
<!ELEMENT element-name (element-content)>

Empty Elements
<!ELEMENT element-name EMPTY>
Example:<!ELEMENT br EMPTY>
XML example:<br />

Elements with Parsed Character Data
<!ELEMENT element-name (#PCDATA)>
Example:<!ELEMENT from (#PCDATA)>

Elements with any Contents
<!ELEMENT element-name ANY>
Example:<!ELEMENT note ANY>

Elements with Children (sequences)
<!ELEMENT element-name (child1)>     only one
<!ELEMENT element-name (child1+)>   minimum one
<!ELEMENT element-name (child1*)>    zero or more
<!ELEMENT element-name (child1?)>    zero or one
<!ELEMENT element-name (child1,child2,...)>
Example:<!ELEMENT note (to,from,heading,body)>
<!ELEMENT note (to,from,(heading|body))>

Declaring Attributes
<!ATTLIST element-name attribute-name attribute-type default-value>
DTD example:<!ATTLIST payment type CDATA "check">
XML example:<payment type="check" />

Type Description

CDATA

The value is character data

(en1|en2|..)

The value must be one from an enumerated list

ID

The value is a unique id

IDREF

The value is the id of another element

IDREFS

The value is a list of other ids

NMTOKEN

The value is a valid XML name

NMTOKENS

The value is a list of valid XML names

ENTITY

The value is an entity

ENTITIES

The value is a list of entities

NOTATION

The value is a name of a notation

xml:

The value is a predefined xml value

Value Explanation

value

The default value of the attribute

#REQUIRED

The attribute is required

#IMPLIED

The attribute is not required

#FIXED value

The attribute value is fixed

Entities are variables used to define shortcuts to standard text or special characters.
An Internal Entity Declaration
<!ENTITY entity-name "entity-value">
DTD Example:
<!ENTITY writer "Donald Duck.">
<!ENTITY copyright "Copyright W3Schools.">
XML example:<author>&writer;&copyright;</author>

An External Entity Declaration
<!ENTITY entity-name SYSTEM "URI/URL">
DTD Example:
<!ENTITY writer SYSTEM "http://www.w3schools.com/entities.dtd">
<!ENTITY copyright SYSTEM "http://www.w3schools.com/entities.dtd">
XML example:<author>&writer;&copyright;</author>

TV Schedule DTD

<!DOCTYPE CATALOG [
  <!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)>

]>

* Reference to W3C Schools