如何在XML中注释掉一个标记块?
即我如何<staticText>在下面的代码中注释掉它里面的所有内容?
<detail>
<band height="20">
<staticText>
<reportElement x="180" y="0" width="200" height="20"/>
<text><![CDATA[Hello World!]]></text>
</staticText>
</band>
</detail>
Run Code Online (Sandbox Code Playgroud)
我可以使用,<!-- staticText-->但这只是用于单个标签(就像我所知道的那样),就像//在Java和C中一样.我想更像是如何/** comment **/在Java和C中使用,所以我可以注释掉更长的XML代码块.
Noo*_*ilk 1107
您可以跨多行使用该样式的注释(也存在于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>
Run Code Online (Sandbox Code Playgroud)
Kas*_*erg 162
您可以使用不存在的处理指令包装文本,例如:
<detail>
<?ignore
<band height="20">
<staticText>
<reportElement x="180" y="0" width="200" height="20"/>
<text><![CDATA[Hello World!]]></text>
</staticText>
</band>
?>
</detail>
Run Code Online (Sandbox Code Playgroud)
不允许嵌套处理指令,'?>'结束处理指令(参见http://www.w3.org/TR/REC-xml/#sec-pi)
Bol*_*wyn 146
如果你问,因为你的<!-- -->语法有错误,那很可能就是CDATA部分(以及]]>部分),然后它就在评论的中间.它应该没有什么区别,但理想和现实世界有时相隔很远(特别是在XML处理方面).
也尝试改变]]>:
<!--detail>
<band height="20">
<staticText>
<reportElement x="180" y="0" width="200" height="20"/>
<text><![CDATA[Hello World!]--><!--]></text>
</staticText>
</band>
</detail-->
Run Code Online (Sandbox Code Playgroud)
另一件事,我想到:如果您的XML内容包含两个连字符,则注释会立即结束:
<!-- <a> This is strange -- but true!</a> -->
--------------------------^ comment ends here
Run Code Online (Sandbox Code Playgroud)
这是一个很常见的陷阱.它继承自SGML处理注释的方式.(阅读关于此主题的XML规范)
Del*_*ani 47
实际上,您可以将<!--...-->格式与多行或标记一起使用:
<!--
...
...
...
-->
Run Code Online (Sandbox Code Playgroud)
Avi*_*kar 23
在这里评论我们必须写如下:
<!-- Your comment here -->
Run Code Online (Sandbox Code Playgroud)
对于Windows和Linux:
评论单行的快捷方式:
Ctrl + /
注释多行的快捷方式:
Ctrl+ Shift+/
对于Mac:
评论单行的快捷方式:
cmnd + /
注释多行的快捷方式:
cmnd+ Shift+/
有一点你必须记住,你不能评论XML标签的属性.例如:
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
<!--android:text="Hello.."-->
android:textStyle="bold" />
Run Code Online (Sandbox Code Playgroud)
这TextView是XML标记,text是该标记的属性.您无法评论XML标记的属性.您必须评论完整的XML标记.例如:
<!--<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello.."
android:textStyle="bold" />-->
Run Code Online (Sandbox Code Playgroud)
小智 11
您可以使用以下方法轻松注释掉数据:
<!--
<data>
<data-field1></data-field1>
<data-field2></data-field2>
<data-field3></data-field3>
</data>
-->
Run Code Online (Sandbox Code Playgroud)
在xml中注释的方法.
Sum*_*mit 11
XML 语法:
<!--Your comment-->
例如。
Run Code Online (Sandbox Code Playgroud)<?xml version = "1.0" encoding = "UTF-8" ?> <!--here is your comment :) --> <class_list> <student> <name></name> <grade>A</grade> </student> </class_list>
XML 注释规则
Comments cannot appear before XML declaration.
Comments may appear anywhere in a document.
Comments must not appear within attribute values.
Comments cannot be nested inside the other comments.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1710218 次 |
| 最近记录: |