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.8. 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.9. Erroneous XML Comments
<!-- This is in the comment --


  -- back inside the comment -->

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


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 <freebsd-questions@FreeBSD.org>.
Send questions about this document to <freebsd-doc@FreeBSD.org>.