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).
- 允许或者禁止出现的元素类型的名字(例如:UL元素包含LI元素类型的实例,P元素类型不可以再包含其他的P元素)。
- DTD entities (e.g., the LABEL element contains instances of the “%inline;” parameter entity).
- DTD实体(例如:LABEL元素可以包含所有参数实体”%inline”型的实例)。
- 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é’s adventures of Tintin” contains the character entity reference for the “eacute” character).
- 文档文本(采用SGML基础构件”#PCDATA”表示)。文本可以包含字符引用。回忆一下:字符引用是以”&”开开始以分号结束(例如: “Hergé’s adventures of Tintin”包含了对”eacute”字符的字符实体引用)。
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.
元素的内容模型要采用下面的语法来进行描述。请注意下面的列表只是SGML语法规则全集的简化版本,并不涉及比如优先级等其他复杂规则。
-
( … )
- Delimits a group.
- 界定一个组。
- 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必须不出现。
- 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。
- A和B必须出现,顺序随意。
A
A+
A?
A*
+(A)
-(A)
A | B
A , B
A & B
Here are some examples from the HTML DTD:
下面是来自 HTML DTD的例子:
<!ELEMENT UL - - (LI)+>
The UL element must contain one or more LI elements.
UL元素必须至少包含一个LI元素
<!ELEMENT DL - - (DT|DD)+>
The DL element must contain one or more DT or DD elements in any order.
DL元素必须包含一个以上(含一个)DT或DD元素,DT和DD元素的顺序随意。
<!ELEMENT OPTION - O (#PCDATA)>
The OPTION element may only contain text and entities, such as & — this is indicated by the SGML data type #PCDATA.
根据SGML对#PCDATA的定义,OPTION 元素仅能包含文本和类似于&的实体。
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.
少数几个元素类型为了可以将某些元素从他们的内容中清除出去,他们使用了附加的SGML特性。被排除的元素以连词符为前缀。显式排除规则覆盖允许的规则。
In this example, the -(A) signifies that the element A cannot appear in another A element (i.e., anchors may not be nested).
在下面的例子中,-(A)指明了A不能再另外一个A元素中出现(例如:锚定点不能嵌套)。
<!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).
请注意,A元素类型是DTD参数实体”%inline”的一部分,但是通过显式的排除方式-(A)将其从允许的集合中去掉了。
Similarly, the following element type declaration for FORM prohibits nested forms:
类似的,下面的FORM元素类型声明中禁止了嵌套的FORM。
<!ELEMENT FORM - - (%block;|SCRIPT)+ -(FORM)>
3.3.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:
元素能够拥有的属性声明以关键字<!ATTLIST开始。后接属于的元素名以及属性定义列表,最后以>结束。每一个属性定义都是一个三段式结构:
- 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.
- 属性值的类型或者是允许取值的集合。在DTD中显式定义的取值是大小写不敏感。对于关于属性值类型的更多信息请参阅《HTML基础数据类型》部分。
- 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.
- 属性的缺省值是否是隐含的(关键字”#IMPILED”),如果是隐含的情况,那么用户代理就必须为属性提供缺省值,比如在有些情况下是继承自父元素。属性值是否是必须的(关键字 “#REQUIRED”);属性值是否是固定的(关键字”#FIXED”)。有些属性的定义会明确的给出这个属性的缺省值。
In this example, the name attribute is defined for the MAP element. The attribute is optional for this element.
下面的例子是为MAP元素定义的name属性。该属性对于该元素来讲是可选的。
<!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.
在上面的例子中name属性允许的取值为CDATA型,CDATA是一种SGML数据类型。它是一个可以包含字符引用的文本。
For more information about “CDATA”, “NAME”, “ID”, and other data types, please consult the section on HTML data types.
关于”CDATA”,”NAME”,”ID”以及其他数据类型的更多信息,请参阅HTML数据类型部分。
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}.
rowspan 属性要求NUMBER类型的值。它的缺省值显式定义为”1″。可选的http-equiv属性要求NAME类型的值。可选的id属性要求ID类型的值。可选的valign属性被限制成只能是{top, middle, bottom, baseline}集合中的值。
DTD entities in attribute definitions
属性定义中的DTD实体
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.
在下面的例子中,我们可以看到LINK元素的属性定义列表是以参数实体”%attrs”开头的。
<!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:
参数实体”%attrs;”的定义如下:
<!ENTITY % attrs "%coreattrs; %i18n; %events;">
The “%coreattrs;” parameter entity in the “%attrs;” definition expands as follows:
“%attrs;”中的参数实体”%coreattrs;”的定义如下:
The “%attrs;” parameter entity has been defined for convenience since these attributes are defined for most HTML element types.
参数实体”%attrs”定了了绝大多数HTML元素类型都需要的属性,它可以被用来简化DTD的书写和组织。
Similarly, the DTD defines the “%URI;” parameter entity as expanding into the string “CDATA”.
类似的,DTD定义了”%URI”参数实体作为一个”CDATA”字符串。
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.
作为验证的例子,参数实体”%URI”给读者提供了更多的关于属性值数据类型的信息。相似的实体还有:”%Color;”, “%Charset;”, “%Length;”, “%Pixels;”等
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”.
有一些属性充当布尔变量,例如:OPTION元素selected属性。如果他们出现在元素的开始标签中就意味着这个属性的值是”true”,相反如果不出现就意味着属性取值为”false”。
Boolean attributes may legally take a single value: the name of the attribute itself (e.g., selected=”selected”).
布尔型属性原则上可以有一个单一的值:属性本身的名字(例如:selected=”selected”)。
This example defines the selected attribute to be a boolean attribute.
下面的例子是把selected的属性定义为布尔型属性。
selected (selected) #IMPLIED -- option is pre-selected --
The attribute is set to “true” by appearing in the element’s start tag:
通过将该属性放置在元素的开始标签中,该属性的值被设置为”true”:
<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:
在HTML语境中,布尔型属性可以采用最小化形式来表述——只需要在元素的开始标签中出现属性值。在这样的背景下,selected可以通过下吗的写法来设定”true”:
<OPTION selected>
而无需使用如下写法:
<OPTION selected=”selected”>
Authors should be aware that many user agents only recognize the minimized form of boolean attributes and not the full form.
HTML文档的作者应该了解如下事实:很多用户代理(浏览器)只能识别最小化形式的布尔型属性而不能识别完×××式。
转载于:https://blog.51cto.com/pppcode/595491
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/110605.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...