DTD 定义中的注释
Comments in DTD definitions
在查看 HTML 4 dtd (https://www.w3.org/TR/html4/sgml/dtd.html) 时,我在 dtd 定义中看到了很多描述性注释。
<!ELEMENT A - - (%inline;)* -(A) -- anchor -->
<!ATTLIST A
%attrs; -- %coreattrs, %i18n, %events --
charset %Charset; #IMPLIED -- char encoding of linked resource --
type %ContentType; #IMPLIED -- advisory content type --
name CDATA #IMPLIED -- named link end --
href %URI; #IMPLIED -- URI for linked resource --
hreflang %LanguageCode; #IMPLIED -- language code --
rel %LinkTypes; #IMPLIED -- forward link types --
rev %LinkTypes; #IMPLIED -- reverse link types --
accesskey %Character; #IMPLIED -- accessibility key character --
shape %Shape; rect -- for use with client-side image maps --
coords %Coords; #IMPLIED -- for use with client-side image maps --
tabindex NUMBER #IMPLIED -- position in tabbing order --
onfocus %Script; #IMPLIED -- the element got the focus --
onblur %Script; #IMPLIED -- the element lost the focus --
>
我知道这是一个 SGML dtd。当我尝试在我的 XML dtds 中引入它们时,我从处理器收到解析错误。这些注释是否已从 XML 的 DTD 变体中删除?
post.dtd:36: parser error : expected '>'
<!ELEMENT A (#PCDATA) -- a link -- >
^
post.dtd:36: parser error : Content error in the external subset
<!ELEMENT A (#PCDATA) -- a link -- >
根据 X3 XML 1.0 规范,DTD 声明中允许注释。然而,它们是 XML 风格的评论,以 <!--
开头并以 -->
结尾,正如之前的评论者所指出的那样。有关语法详细信息,请参阅 https://www.w3.org/TR/2008/REC-xml-20081126/#NT-DeclSep。
但是,它们并未像上面的示例那样嵌入到元素或属性列表声明中。来自 XHTML DTD 的示例使用带有注释的 XML DTD 语法描述元 HTML 标记。完整的 dtd 位于:https://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd
<!ELEMENT meta EMPTY>
<!ATTLIST meta
%i18n;
id ID #IMPLIED
http-equiv CDATA #IMPLIED
name CDATA #IMPLIED
content CDATA #REQUIRED
scheme CDATA #IMPLIED
>
<!--
Relationship values can be used in principle:
a) for document specific toolbars/menus when used
with the link element in document head e.g.
start, contents, previous, next, index, end, help
b) to link to a separate style sheet (rel="stylesheet")
c) to make a link to a script (rel="script")
d) by stylesheets to control how collections of
html nodes are rendered into printed documents
e) to make a link to a printable version of this document
e.g. a PostScript or PDF version (rel="alternate" media="print")
-->
在 SGML 中,以 --
开头和结尾的注释可以出现在标记声明中的任何地方或多次;在 XML 中,一个标记声明必须只包含一个注释,或者另一个标记声明:
<!-- valid in XML -->
<!-- only -- -- valid -- -- in -- -- SGML -->
由于 XML 被定义为 SGML 子集,文本字符串 --
不允许出现在任何地方的 XML 评论中。
在查看 HTML 4 dtd (https://www.w3.org/TR/html4/sgml/dtd.html) 时,我在 dtd 定义中看到了很多描述性注释。
<!ELEMENT A - - (%inline;)* -(A) -- anchor -->
<!ATTLIST A
%attrs; -- %coreattrs, %i18n, %events --
charset %Charset; #IMPLIED -- char encoding of linked resource --
type %ContentType; #IMPLIED -- advisory content type --
name CDATA #IMPLIED -- named link end --
href %URI; #IMPLIED -- URI for linked resource --
hreflang %LanguageCode; #IMPLIED -- language code --
rel %LinkTypes; #IMPLIED -- forward link types --
rev %LinkTypes; #IMPLIED -- reverse link types --
accesskey %Character; #IMPLIED -- accessibility key character --
shape %Shape; rect -- for use with client-side image maps --
coords %Coords; #IMPLIED -- for use with client-side image maps --
tabindex NUMBER #IMPLIED -- position in tabbing order --
onfocus %Script; #IMPLIED -- the element got the focus --
onblur %Script; #IMPLIED -- the element lost the focus --
>
我知道这是一个 SGML dtd。当我尝试在我的 XML dtds 中引入它们时,我从处理器收到解析错误。这些注释是否已从 XML 的 DTD 变体中删除?
post.dtd:36: parser error : expected '>'
<!ELEMENT A (#PCDATA) -- a link -- >
^
post.dtd:36: parser error : Content error in the external subset
<!ELEMENT A (#PCDATA) -- a link -- >
根据 X3 XML 1.0 规范,DTD 声明中允许注释。然而,它们是 XML 风格的评论,以 <!--
开头并以 -->
结尾,正如之前的评论者所指出的那样。有关语法详细信息,请参阅 https://www.w3.org/TR/2008/REC-xml-20081126/#NT-DeclSep。
但是,它们并未像上面的示例那样嵌入到元素或属性列表声明中。来自 XHTML DTD 的示例使用带有注释的 XML DTD 语法描述元 HTML 标记。完整的 dtd 位于:https://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd
<!ELEMENT meta EMPTY>
<!ATTLIST meta
%i18n;
id ID #IMPLIED
http-equiv CDATA #IMPLIED
name CDATA #IMPLIED
content CDATA #REQUIRED
scheme CDATA #IMPLIED
>
<!--
Relationship values can be used in principle:
a) for document specific toolbars/menus when used
with the link element in document head e.g.
start, contents, previous, next, index, end, help
b) to link to a separate style sheet (rel="stylesheet")
c) to make a link to a script (rel="script")
d) by stylesheets to control how collections of
html nodes are rendered into printed documents
e) to make a link to a printable version of this document
e.g. a PostScript or PDF version (rel="alternate" media="print")
-->
在 SGML 中,以 --
开头和结尾的注释可以出现在标记声明中的任何地方或多次;在 XML 中,一个标记声明必须只包含一个注释,或者另一个标记声明:
<!-- valid in XML -->
<!-- only -- -- valid -- -- in -- -- SGML -->
由于 XML 被定义为 SGML 子集,文本字符串 --
不允许出现在任何地方的 XML 评论中。