7.5. Comments

Comments are an XML construct, and are normally only valid inside a DTD. However, as Section 7.4, “Escaping Back to XML shows, it is possible to use XML syntax within the document.

The delimiter for XML comments is the string --. The first occurrence of this string opens a comment, and the second closes it.

Example 7.6. XML Generic Comment
<!-- This is inside the comment -->

<!-- This is another comment    -->

<!-- This is one way
     of doing multiline comments -->

<!-- This is another way of   --
  -- doing multiline comments -->

XHTML users may be familiar with different rules for comments. In particular, it is often believed that the string <!-- opens a comment, and it is only closed by -->.

This is not correct. Many web browsers have broken XHTML parsers, and will accept incorrect input as valid. However, the XML parsers used by the Documentation Project are more strict, and will reject documents with that error.

Example 7.7. Erroneous XML Comments
<!-- This is in the comment --

     THIS IS OUTSIDE THE COMMENT!

  -- back inside the comment -->

The XML parser will treat this as though it were actually:

<!THIS IS OUTSIDE THE COMMENT>

That is not valid XML, and may give confusing error messages.


7.5.1. To Do…

  1. Add some comments to example.xml, and check that the file still validates using xmllint.

  2. Add some invalid comments to example.xml, and see the error messages that xmllint gives when it encounters an invalid comment.

All FreeBSD documents are available for download at http://ftp.FreeBSD.org/pub/FreeBSD/doc/

Questions that are not answered by the documentation may be sent to <[email protected]>.
Send questions about this document to <[email protected]>.