2

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 -- >
wirrbel
  • 3,173
  • 3
  • 26
  • 49
  • IIRC, XML comments are only allowed in their own declarations (and exactly one comment, without leading or trailing whitespace - so they always begin with ``). I'm pretty sure the XML group decided not to allow comments within other declarations (but it was over 20 years ago now, and my memory's getting hazy). – Toby Speight May 29 '18 at 10:30

2 Answers2

2

According to the X3 XML 1.0 specification comments are allowed in the DTD declaration. However, they are XML style comments starting with <!-- and ending with --> as the previous commentor noted. See https://www.w3.org/TR/2008/REC-xml-20081126/#NT-DeclSep for the syntax details.

However, they are not embedded inside the Element or Attribute List declarations like the sample above. Example from the XHTML DTD describes the meta HTML tag using an XML DTD syntax with comments. Full dtd at: 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")
-->
John Horman
  • 121
  • 4
2

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.

imhotap
  • 2,275
  • 1
  • 8
  • 16