Is there any particular reason (other than it would make the parsing harder) that XML doesn’t allow nesting comments, i.e. something like
<!--
<!-- this is the foo element -->
<foo>bar</foo>
-->
?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Presumably, it’s for the same reason that you can’t nest tags:
A comment is really just one kind of tag, and the same rules apply to comments as to any other tag.Update: Quentin properly points out that a comment is, in fact, not a tag. It’s a different thing altogether. What is true, though, is that comments follow the same delimiter-content-delimeter pattern that tags do. Compare the rule for comments (15) to the rule for empty tags (44) and the rules for start tags (40, 41), and contrast those with the rule for elements (39). Elements can be nested (43), but an element is (back to 39) a start_tag-content-end_tag combination where the content part can be an element. A comment, again, works like an individual tag, not like an element.
Now, all that explains that comments can’t be nested, but not why it was designed that way. I don’t know enough about the history of XML to say what was in the hearts of its designers, but XML is “an application” of the even more general SGML. It was also developed well after the introduction of HTML and was intended in part to address some of the flaws in HTML. SGML and HTML share the same syntax for comments, and it’s obvious just by looking that XML inherited that same syntax. One has to imagine, then, that XML comments work they way they do largely because they were inherited from its predecessors: the decision had been made before XML development even got underway.