In XML comments, two consecutive -- are not allowed. Why?

In XML comments, two consecutive -- are not allowed. Why?

    Requires Free Membership to View

This restriction dates back to the SGML days.
In SGML, the comment start string "<!-- hello world-->" is actually a combination of five things. The first bit is "<!" and is known as "Markup declaration open" or "mdo" for short. The second bit is "--" and is known as "comment delimiter" or "com" for short. Then comes the string "hello world". The fourth piece is "--" which is "com" again. The final, fifth piece is ">" which is known as "markup declaration close" or mdc for short.

In SGML the full comment "<!-- hello world -->" is seen by the parser as:
MDO COM hello world COM MDC.

So, the reason for the restriction on "--" is that as far as the parsing rules are concerned, the "--" is the delimiter of a comment and so cannot occur within one.

Consideration was taken to removing this restriction during the early days of discussions about the shape of XML but it was decided to leave it as is eventually.

This was first published in April 2004

Join the conversationComment

Share
Comments

    Results

    Contribute to the conversation

    All fields are required. Comments will appear at the bottom of the article.