I was applying markdown comments in the xml comments of a config file when the XmlParser reported that two hyphens (--
) are not allowed in xml comments.
Checking the XML Specification, it appears that xml comment isn’t designed to contain two hyphens for compatibility reasons with SGML parsers.
Why do SGML parsers disallow double hyphens in comments?
3
This page outlines quite a bit of the HTML/SGML history, and the rather convoluted rules of those two consecutive hyphens (double dash).
The relevant part about SGML:
To put it simply, the double dash at the start and end of the comment do not start and end the comment. Double dash indicates a change in what the comment is allowed to contain. The first — starts the comment, and tells the browser that the comment is allowed to contain > characters without ending the comment. The second — does not end the comment. It tells the browser that if it encounters a > character, it must then end the comment. If another — is added, then it goes back to allowing the > characters.
3
Because a double hyphen is the comment delimiter in SGML. The <!
starts an SGML instruction, the --
indicates the start or end of a comment. So basically it is for the same reason that a C++ comment cannot contain */
.
6