Contents

How to read the HTML DTD

1. DTD Comments

2. Parameter Entity definitions

3. Element declarations

    . Content model definitions

4. Attribute declarations

    . DTD entities in attribute definitions

    . Boolean attributes

How to read the HTML DTD

Each element and attribute declaration in this specification is accompanied by its document type definition fragment. We have chosen to include the DTD fragments in the specification rather than seek a more approachable, but longer and less precise means of describing an element's properties. The following tutorial should allow readers unfamiliar with SGML to read the DTD and understand the technical details of the HTML specificationi.

1. DTD Comments

In DTDs, comments may spread over one or more lines. In the DTD, comments are delimited by a pair of "--" marks, e.g.

<!ELEMENT PARAM - O EMPTY    -- named property value -->

Here, the comment "named property value" explains the use of the PARAM element type. Comments in the DTD are informative only.

2. Parameter entity definitions

The HTML DTD begins with a series of parameter entity definitions. A parameter entity definition defines a kind of macro that be referenced and expanded elsewhere in the DTD. These macros may not appear in HTML documents, only in the DTD. Other types of macros, called character references, may be used in the text of an HTML document or within attribute values.

When the parameter entity is refered to by name in the DTD, it is expanded into a string.

A parameter entity definition begins with the keyword <!ENTITY % followed by the entity name, the quoted string the entity expands to, and finally a closing >. Instances of parameter entities in a DTD begin with "%", then the parameter entity name, and terminated by an optional ";".

The following example defines the string that the "%fontstyle;" entity will expand to.

  <!ENTITY % fontstyle "TT | I | B | BIG | SMALL">

The string the parameter entity expands to may contain other parameter entity names. These names are expanded recursively. In the following example, the "%inline;" parameter entity is defined to include the "%fontstyle;", "%phrase;", "%special;" and "%formctrl;" parameter entities.

  <!ENTITY % inline "#PCDATA | %fontstyle; | %phrase; | %special; | %formctrl;">

You will encounter two DTD entities frequently in the HTML DTD: %block;" %inline;". They are used when the content model includes block-level and inline elements, respectively (defined in the section on the global structure of an HTML document).

3. ELement declarations

The bulk of the HTML DTD consists of the declarations of element types and their attributes. The <!ELEMENT keyword begins a declaration and the > character ends it. Between these are specified:

(1). The element's name.

(2). Whether the element's tags are optional. Two hyphens that appear after the element name mean that the       start and end tags are mandatory. One         hyphen followed by the letter "O" indicates that the end tag can be       omitted. A pair of letter "O"s indicated that both the start and end tags can be         omitted.

(3) The element's content, if any. The allowed content for an element is called its content model. Element types that are designed to have no content are          called empty elements. The content model for such element types is declared using the keyword "EMPTY".

In this example:

  <!ELEMENT UL - - (LI)+>

 . The element type being declared is UL.

. The two hyphens indicate that both the start tag <UL> and the end tag </UL> for this element type are          required.

. The content model for this element type is declared to be "at least one LI element". Below, we explain how

to specify content models.

This example illustrates the declaration of an empty element type:

  <!ELEMENT IMG - O EMPTY>

. The element type being declared is IMG.

 . The hyphen and the following "O" indicate that the end tag can be omitted, but together with the content

model "EMPTY", this is strengthened to the rule that the end tag must be omitted.

 . The "EMPTY" keyword means that instances of this type must not have content.

Content model definitions

The content model describes what may be contained by an instance of an element type. Content model definitions may include:

The names of allowed or forbidden element types (e.g., the UL element contains instances of the LI element type, and the P element type may not contain other P elements).
DTD entities (e.g., the LABEL element contains instances of the "%inline;" parameter entity).
Document text (indicated by the SGML construct "#PCDATA"). Text may contain character references. Recall that these begin with & and end with a semicolon (e.g., "Herg&eacute;'s adventures of Tintin" contains the character entity reference for the "e acute" character).
The content model of an element is specified with the following syntax. Please note that the list below is a simplification of the full SGML syntax rules and does not address, e.g., precedences.

( ... )
Delimits a group.
A
A must occur, one time only.
A+
A must occur one or more times.
A?
A must occur zero or one time.
A*
A may occur zero or more times.
+(A)
A may occur.
-(A)
A must not occur.
A | B
Either A or B must occur, but not both.
A , B
Both A and B must occur, in that order.
A & B
Both A and B must occur, in any order.
Here are some examples from the HTML DTD:

<!ELEMENT UL - - (LI)+>
The UL element must contain one or more LI elements.

<!ELEMENT DL - - (DT|DD)+>
The DL element must contain one or more DT or DD elements in any order.

<!ELEMENT OPTION - O (#PCDATA)>
The OPTION element may only contain text and entities, such as &amp; -- this is indicated by the SGML data type #PCDATA.

A few HTML element types use an additional SGML feature to exclude elements from their content model. Excluded elements are preceded by a hyphen. Explicit exclusions override permitted elements.

In this example, the -(A) signifies that the element A cannot appear in another A element (i.e., anchors may not be nested).

<!ELEMENT A - - (%inline;)* -(A)>
Note that the A element type is part of the DTD parameter entity "%inline;", but is excluded explicitly because of -(A).

Similarly, the following element type declaration for FORM prohibits nested forms:

<!ELEMENT FORM - - (%block;|SCRIPT)+ -(FORM)>

4. Attribute declarations

The <!ATTLIST keyword begins the declaration of attributes that an element may take. It is followed by the name of the element in question, a list of attribute definitions, and a closing >. Each attribute definition is a triplet that defines:

. The name of an attribute.
. The type of the attribute's value or an explicit set of possible values. Values defined explicitly by the DTD are case-insensitive. Please consult the section on   basic HTML data types for more information about attribute value types.
. Whether the default value of the attribute is implicit (keyword "#IMPLIED"), in which case the default value must be supplied by the user agent (in some       cases via inheritance from parent elements); always required (keyword "#REQUIRED"); or fixed to the given value (keyword "#FIXED"). Some attribute         definitions explicitly specify a default value for the attribute.
In this example, the name attribute is defined for the MAP element. The attribute is optional for this element.

<!ATTLIST MAP
name CDATA #IMPLIED
>
The type of values permitted for the attribute is given as CDATA, an SGML data type. CDATA is text that may contain character references.

For more information about "CDATA", "NAME", "ID", and other data types, please consult the section on HTML data types.

The following examples illustrate several attribute definitions:

rowspan NUMBER 1 -- number of rows spanned by cell --
http-equiv NAME #IMPLIED -- HTTP response header name --
id ID #IMPLIED -- document-wide unique id --
valign (top|middle|bottom|baseline) #IMPLIED
The rowspan attribute requires values of type NUMBER. The default value is given explicitly as "1". The optional http-equiv attribute requires values of type NAME. The optional id attribute requires values of type ID. The optional valign attribute is constrained to take values from the set {top, middle, bottom, baseline}.

DTD entities in attribute definitions

Attribute definitions may also contain parameter entity references.

In this example, we see that the attribute definition list for the LINK element begins with the "%attrs;" parameter entity.

<!ELEMENT LINK - O EMPTY -- a media-independent link -->
<!ATTLIST LINK
%attrs; -- %coreattrs, %i18n, %events --
charset %Charset; #IMPLIED -- char encoding of linked resource --
href %URI; #IMPLIED -- URI for linked resource --
hreflang %LanguageCode; #IMPLIED -- language code --
type %ContentType; #IMPLIED -- advisory content type --
rel %LinkTypes; #IMPLIED -- forward link types --
rev %LinkTypes; #IMPLIED -- reverse link types --
media %MediaDesc; #IMPLIED -- for rendering on these media --
>
Start tag: required, End tag: forbidden

The "%attrs;" parameter entity is defined as follows:

<!ENTITY % attrs "%coreattrs; %i18n; %events;">
The "%coreattrs;" parameter entity in the "%attrs;" definition expands as follows:

<!ENTITY % coreattrs
"id ID #IMPLIED -- document-wide unique id --
class CDATA #IMPLIED -- space-separated list of classes --
style %StyleSheet; #IMPLIED -- associated style info --
title %Text; #IMPLIED -- advisory title --"
>
The "%attrs;" parameter entity has been defined for convenience since these attributes are defined for most HTML element types.

Similarly, the DTD defines the "%URI;" parameter entity as expanding into the string "CDATA".

<!ENTITY % URI "CDATA"
-- a Uniform Resource Identifier,
see [URI]
-->
As this example illustrates, the parameter entity "%URI;" provides readers of the DTD with more information as to the type of data expected for an attribute. Similar entities have been defined for "%Color;", "%Charset;", "%Length;", "%Pixels;", etc.

Boolean attributes

Some attributes play the role of boolean variables (e.g., the selected attribute for the OPTION element). Their appearance in the start tag of an element implies that the value of the attribute is "true". Their absence implies a value of "false".

Boolean attributes may legally take a single value: the name of the attribute itself (e.g., selected="selected").

This example defines the selected attribute to be a boolean attribute.

selected (selected) #IMPLIED -- option is pre-selected --
The attribute is set to "true" by appearing in the element's start tag:

<OPTION selected="selected">
...contents...
</OPTION>
In HTML, boolean attributes may appear in minimized form -- the attribute's value appears alone in the element's start tag. Thus, selected may be set by writing:

<OPTION selected>
instead of:

<OPTION selected="selected">
Authors should be aware that many user agents only recognize the minimized form of boolean attributes and not the full form.

How to read the HTML DTD的更多相关文章

  1. hibernate-mapping-3.0.dtd;hibernate-configuration-3.0.dtd;hibernate.properties所在路径

    hibernate-mapping-3.0.dtd 所在路径:hibernate-release-5.2.5.Final\project\hibernate-core\src\main\resourc ...

  2. xml中DTD解析

    DTD的作用是"文档类型的定义" DTD申明始终以<!DOCTYPE开头(开头后空一格). 本标签一共有三种写法 一.内部DTD: <!DOCTYPE 根元素 [ 文档 ...

  3. 那点你不知道的XHtml(Xml+Html)语法知识(DTD、XSD)

    什么是XHtml: 摘录网上的一句话,XHTML就是一个扮演着类似HTML的角色的XML. XHtml可当模板引擎应用: CYQ.Data 框架里有一套XHtmlAction模板引擎, 应用在QBlo ...

  4. XML语言基础2 DTD

    XML DTD 文档类型定义(DTD)可定义合法的XML文档构建模块.它使用一系列合法的元素来定义文档结构. DTD可被声明于XML文档中,也可以作为一个外部的引用. 内部的DOCTYPE声明 假如D ...

  5. DTD总结

    DTD 可以检测 XNM 文档的结构是否正确,就好像文章中用来保证结构正确的语法规则一样. 引入 DTD 1.引入私有的 DTD 文件,URI 可以使相对地址或绝对地址 <!DOCTYPE 根元 ...

  6. xml引用实体dtd不能成功的问题

    你没有错,现在的浏览器都不怎么支持实体引用了,这是个无奈的现实.我记得上回试过,好像如果DTD不是单独的文件而是内置到XML里面的话,实体还可以显示的.你可以试一下 <?xml version= ...

  7. DTD文档模型和HTML基础

    html是超文本标记语言,现在常用到的2中文档格式是html5和XHTML 1.0 Transitiona(过渡). <!DOCTYPE html> <!--当前文档为html5-- ...

  8. xml dtd 定义元素

    ANY 如果需要定义某个元素的值可以是任意类型,可采用如下语法 <!ELEMENT 元素名 ANY> DTD必须定义XML文档中允许出现的所有元素,所以下面这样是不行的,因为<hel ...

  9. xml dtd 内部dtd 外部DTD 公共DTD

    (一个可以用来校验xml有效性的网站:http://www.xmlvalidation.com/) (经测试 eclipse neon 对于dtd的校验并不严格,比如DOCTYPE后面的根元素名与实际 ...

  10. DTD的作用

    在介绍DTD的作用之前先介绍一下SGML:SGML SGML(Standard Generalized Markup Language,标准通用标记语言),是一种定义电子文档结构和描述其内容的国际标准 ...

随机推荐

  1. 用C语言实现素数筛法获取一亿(100000000)以内的全部素数

    具体筛法是:先把n个自然数按次序排列起来.1不是质数,也不是合数,要划去.第二个数2是质数留下来,而把2后面所有能被2整除的数都划去.2后面第一个没划去的数是3,把3留下,再把3后面所有能被3整除的数 ...

  2. JSONP - 跨域AJAX

    基础概念 在进入本文正题之前,我们需要先了解一些基础概念(如果你已经对这些基础有所了解,可跳过此段落). 同源策略和跨域概念 同源策略(Same-orgin policy)限制了一个源(orgin)中 ...

  3. Powershell的远程管理

    powershell有强大的远程管理功能,但是现在遇到个问题,我们之前的客户端操作系统都是默认安装的,没做默认设置,请问如何通过gpo将所有和远程有关的设置都搞定啊?到底要设置哪些个选项?   我的环 ...

  4. [办公自动化] 再读《让EXCEL飞》(从excel导入access数据时,union联合查询,数据源中没有包含可见的表格)

    一年多以前就买了@Mrexcel的<让excel飞>这本书.整体思路是利用access结合excel,大幅度提高数据分析效率. 最近又拿出来看了看.第十五章,比高级筛选更“高级”,P241 ...

  5. Radeon HD 7850 vs Radeon R9 270X

    Radeon HD 7850 vs Radeon R9 270X  HW compare   Intro The Radeon HD 7850 comes with a GPU core speed ...

  6. flowvisor test(1)

    参考: Flowvisor 入门 杨帅老师:mininet+FlowVisor+ODL环境搭建及实验1 安装: 参考: 1.Flowvisor安装 2.Mininet安装 3.官网,Floodligh ...

  7. MySQL DATE_FORMAT() 函数

    定义和用法 DATE_FORMAT() 函数用于以不同的格式显示日期/时间数据. 语法 DATE_FORMAT(date,format) date 参数是合法的日期.format 规定日期/时间的输出 ...

  8. zabbix 2.2.2在centos 6.3 x86_64上的安装

    zabbix 2.2.2在centos 6.3 x86_64上的安装   更新五月 03, 2014     # 依赖环境 yum install -y php-mbstring mysql-deve ...

  9. the core or essence of a computer

    COMPUTER ORGANIZATION AND ARCHITECTURE DESIGNING FOR PERFORMANCE NINTH EDITION The ALU is that part ...

  10. ThinkPad告别蓝快,自己使用VHD安 WIN8.1并成功激活

    写在前面:本文WIN8.1激活适合于中国大陆地区国行预装WIN8系统(bios写入WIN8授权)是可激活的,享受正版WIN8系统(同样可以安装WIN8.1系统).比如联想的Y400.Y500.Y480 ...