Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question
    
I don't think you will get a better answer than "because that's what the standard says" –  jk. May 17 '13 at 12:11
    
Well, it's that's the only answer, then I have no choice :-(, though there might be better answer than that. –  OnesimusUnbound May 17 '13 at 13:12
add comment

2 Answers 2

up vote 16 down vote accepted

This page outlines quite a bit of the HTML/SGML history, and the rather convoluted rules of the 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.

share|improve this answer
3  
The section you're referring to. When I read what the SGML specs intended for -- within the comment, my head spins around on the complexity it will introduce later on. –  OnesimusUnbound May 17 '13 at 14:22
add comment

Because a double hyphen is the comment delimiter in SGML - the < starts an SGML instruction, the -- indicates a comment. So basically it is for the same reason that a C++ comment cannot contain */.

share|improve this answer
1  
I think --> is the comment delimiter. –  OnesimusUnbound May 17 '13 at 13:54
5  
No, it is not. <! starts an SGML instruction, > ends it. Within an SGML instruction -- both starts and ends a comment. –  Jörg W Mittag May 17 '13 at 14:44
2  
Ahh add your comment to the answer, this is illuminating because it means you could write <!someRelevantSgmlTag -- a comment -- someAttribute="blabla" -- another comment --> and the semantic meaning would be <!someRelevantSgmlTag someAttribute="blabla"> –  Jimmy Hoffa May 17 '13 at 15:05
    
Ah, makes sense. --> is actually two tokens, the -- to delimit comment, and > to end SGML instruction. Now, I have an idea on where <![CDATA[ ... ]]> originated. –  OnesimusUnbound May 17 '13 at 15:09
    
I've merged the comment. –  Joris Timmermans May 17 '13 at 15:22
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.