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

推荐订阅源

WordPress大学
WordPress大学
The GitHub Blog
The GitHub Blog
F
Fortinet All Blogs
Cloudbric
Cloudbric
P
Palo Alto Networks Blog
T
Threatpost
T
Tor Project blog
T
Tenable Blog
AWS News Blog
AWS News Blog
Project Zero
Project Zero
L
LangChain Blog
Cyberwarzone
Cyberwarzone
Engineering at Meta
Engineering at Meta
雷峰网
雷峰网
C
CERT Recently Published Vulnerability Notes
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Security Latest
Security Latest
云风的 BLOG
云风的 BLOG
I
Intezer
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Proofpoint News Feed
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
V
Vulnerabilities – Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
MongoDB | Blog
MongoDB | Blog
aimingoo的专栏
aimingoo的专栏
K
Kaspersky official blog
Jina AI
Jina AI
N
News | PayPal Newsroom
T
The Blog of Author Tim Ferriss
D
DataBreaches.Net
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
博客园 - 【当耐特】
Hugging Face - Blog
Hugging Face - Blog
Recorded Future
Recorded Future
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Secure Thoughts
TaoSecurity Blog
TaoSecurity Blog
P
Privacy & Cybersecurity Law Blog
P
Proofpoint News Feed
MyScale Blog
MyScale Blog
IT之家
IT之家
Forbes - Security
Forbes - Security
The Hacker News
The Hacker News
Last Week in AI
Last Week in AI
T
Threat Research - Cisco Blogs
Y
Y Combinator 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