XML comments and "--"

Maybe it can be helpful for someone. I had a problem, that I wanted to comment out a command line parameter in XML that starts with --:

<arg line="-v --line-break 0" />  

so naturally normal way like this

<!-- <arg line="-v --line-break 0" /> -->

didn't work, but I found out, that if the - is replaced by it's UTF-8 equivalent &#x002D; or &#45; it works and can be tolerated inside comments.

So in my case the string

<arg line="-v &#45;&#45;line-break 0" />

is parsed correctly and can be part of comments.

Of course it looks a little ugly, but if someone want to keep a string with -- as comment in his XML - I think it's still better than nothing.


From the standards document:

http://www.w3.org/TR/REC-xml/#sec-comments

[Definition: Comments may appear anywhere in a document outside other markup; in addition, they may appear within the document type declaration at places allowed by the grammar. They are not part of the document's character data; an XML processor may, but need not, make it possible for an application to retrieve the text of comments. For compatibility, the string " -- " (double-hyphen) must not occur within comments.] Parameter entity references must not be recognized within comments.

Tags:

Xml

Comments