xmldtdsgml

Comments in DTD definitions


When looking at the HTML 4 dtd (https://www.w3.org/TR/html4/sgml/dtd.html) I see a lot of descriptive comments within the dtd definitions.

<!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 --

>

I am aware that this is an SGML dtd. When I try to introduce them in my XML dtds, I get parsing errors from the processor. Have thesecomments been removed from the DTD variant for XML?

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 -- >

Solution

  • In SGML, comments starting with and ending in -- can appear anywhere, or multiple times in a markup declaration; in XML, a markup declaration must either contain just a single comment, or another markup declaration:

    <!-- valid in XML -->
    <!-- only -- -- valid -- -- in -- -- SGML -->
    

    As a consequence of XML being defined as an SGML subset, the text string -- isn't allowed to appear in XML comments anywhere.