A comment, <!-- ... -->, may appear anywhere outside other markup, but never inside a tag. Its text is not character data, so < and & need no escaping and entities are not expanded. Older guides say to avoid -- in a comment "for compatibility"; in fact XML 1.0 forbids it outright. Parsers keep comments as comment nodes, which XPath selects with comment():
printf '<catalog>\n <!-- price list -- checked by finance -->\n</catalog>\n' > notes.xml
xmllint --noout notes.xml
xquery -s:booknest-catalog.xml -qs:'/node() ! (if (. instance of comment())
then "comment: " || normalize-space() else "element: " || name())'Output
notes.xml:2: parser error : Double hyphen within comment: <!-- price list ... "comment: BookNest catalog feed: sample data built from the six-book seed catalog." "element: catalog"
The catalog's comment sits in the prolog, so it is a child of the document node alongside <catalog>. Never put data a program needs in a comment: many tools discard comments, and no schema can validate them.
Comment
<!--……--> denotes a comment, and can appear anywhere outside other markup. Not part of any character data, it may or may not allow the XML processor to retrieve the comment text. The characters <, &, etc. may appear in it. Entity references are not recognized within comments. Avoid double hyphens (--) within comments for compatibility reasons.<?xml version="1.0" encoding="UTF-8"?>
<bookslist>
<!-- These are the books in Golden Bookstore. -->
</bookslist>