CMPSoares
CMPSoares

Reputation: 4205

XML: Use comments to manipulate code?

I use XML for configurations but sometimes I want to test new ones and use comments to leave them separated from the rest like this:

<!-- Begin testing block comments -->
<test1>
    something here
</test1>

<test2>
    something else
</test>
<!-- End testing block comments -->

So recently I came across an error after commenting the whole block removin the first closing comment, assuming that it works as C block comments where only the first comment opening is regarded until a closing one is found (i.e. /* /* */). But when I did the following:

<!-- Begin testing block comments >
...
<!-- End testing block comments -->

I still came across configuration errors. Will this mis-comment my code or is it suppose to work like this? Because if it is I suppose something else might have happened...

Upvotes: 1

Views: 40

Answers (1)

Quentin
Quentin

Reputation: 943212

From the specification:

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.

You have such a double-hyphen here:

<!-- Begin testing block comments >
...
<!-- End testing block comments -->
  ^^

Upvotes: 2

Related Questions