XMLでタグのブロックをコメントアウトするにはどうすればいいですか?
例えば、以下のコードのように、<staticText>
とその中のすべてをコメントアウトするにはどうしたらよいでしょうか?
<detail>
<band height="20">
<staticText>
<reportElement x="180" y="0" width="200" height="20"/>
<text><![CDATA[Hello World!]]></text>
</staticText>
</band>
</detail>
しかし、それはJavaやC言語の//
のような単一のタグのためだけのものです(私が知っている限り)。
複数行にまたがるコメントのスタイル(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>
この ]]>
も変えてみてください。
<!--detail>
<band height="20">
<staticText>
<reportElement x="180" y="0" width="200" height="20"/>
<text><![CDATA[Hello World!]--><!--]></text>
</staticText>
</band>
</detail-->
もうひとつ、思いついたことがあります。どこかのXMLの内容に2つのハイフンが含まれている場合、コメントはすぐにそこで終わります。
<!-- <a> This is strange -- but true!</a> -->
--------------------------^ comment ends here
これは非常によくある落とし穴です。これは、SGMLのコメントの扱い方を受け継いでいます。(Read the XML spec on this topic)