【发布时间】:2018-05-30 14:19:53
【问题描述】:
在查看 HTML 4 dtd (https://www.w3.org/TR/html4/sgml/dtd.html) 时,我在 dtd 定义中看到了很多描述性 cmets。
<!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 中引入它们时,我收到来自处理器的解析错误。这些cmets 是否已从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 -- >
【问题讨论】:
-
IIRC,XML cmets 只允许在它们自己的声明中使用(并且只有一个注释,没有前导或尾随空格 - 所以它们总是以
<!--开头并以-->结尾)。我很确定 XML 小组决定不允许在其他声明中使用 cmets(但现在已经是 20 多年前了,我的记忆越来越模糊了)。