Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

How do I comment out a block of tags in XML?

How do I comment out a block of tags in XML?
For example, How might I remark out <staticText> and everything inside it, in the code beneath?
<detail>
<band height="20">
<staticText>
<reportElement x="180" y="0" width="200" height="20"/>
<text><![CDATA[Hello World!]]></text>
</staticText>
</band>
</detail>

I could use <!-- staticText--> but that's just for single tags (as what I know), like // in Java and C. I would like something more like how / comment / can be used in Java and C, so I can comment out longer blocks of XML code.
by

2 Answers

ninja01
You can use that style of comment across multiple lines (which exists also in HTML)

<detail>
<band height="20">
<!--
Hello,
I am a multi-line XML comment
<staticText>
<reportElement x="180" y="0" width="200" height="20"/>
<text><![CDATA[Hello World!]]></text>
</staticText>
-->
</band>
</detail>
MounikaDasa
If you ask, because you got errors with the <!-- --> syntax, it's most likely the CDATA section (and there the ]]> part), that then lies in the middle of the comment. It should not make a difference, but ideal and real world can be quite a bit apart, sometimes (especially when it comes to XML processing).

Try to change the ]]>, too:

<!--detail>
<band height="20">
<staticText>
<reportElement x="180" y="0" width="200" height="20"/>
<text><![CDATA[Hello World!]--><!--]></text>
</staticText>
</band>
</detail-->
Another thing, that comes to mind: If the content of your XML somewhere contains two hyphens, the comment immediately ends there:

<!-- <a> This is strange -- but true!</a> -->
--------------------------^ comment ends here

Login / Signup to Answer the Question.