XML 中的嵌套注释?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1324821/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 12:42:26  来源:igfitidea点击:

Nested comments in XML?

xmlcomments

提问by Laxmikanth Samudrala

Are these nested comments allowed in a XML file?

XML 文件中是否允许使用这些嵌套注释?

<!-- Making only one observation attempting to correct the error code -->
<!-- <component>
       <!-- Result observation template -->
            <!-- <id root="2.16.840.1.113883.19.5.10" extension="103220"/>
     </component> -->

采纳答案by Brent Writes Code

No, the string --is not permitted to appear within comments in XML. So the fact you have --show up inside another comment is going to cause failures.

不,该字符串--不允许出现在 XML 的注释中。因此,您--在另一条评论中出现的事实将导致失败。

And trying to post that answer also broke the text entry parsing ;)

并尝试发布该答案也破坏了文本条目解析;)

For further proof, check the W3C specification:

如需进一步证明,请查看 W3C 规范:

http://www.w3.org/TR/2008/REC-xml-20081126/#sec-comments

http://www.w3.org/TR/2008/REC-xml-20081126/#sec-comments

The phrase

词组

For compatibility, the string " -- " (double-hyphen) MUST NOT occur within comments.]

为了兼容性,字符串“--”(双连字符)不得出现在注释中。]

appears in the first paragraph of the section on XML comments.

出现在 XML 注释部分的第一段中。

回答by psychoslave

As it is said in How do I comment out a block of tags in XML?, you can try to wrap your code with a non-existing processing-instruction, e.g.:

正如如何在 XML 中注释掉标签块中所说的那样?,您可以尝试使用不存在的处理指令包装您的代码,例如:

<?ignore
<component>
       <!-- Result observation template -->
            <!-- <id root="2.16.840.1.113883.19.5.10" extension="103220"/>
     </component> 
?>

回答by annakata

In a word - no.

一句话—​​—不。

The first encountered end-comment marker will, er... end the comment and the rest of it will look somewhat unpleasant from there on out.

第一个遇到的结束评论标记将,呃...结束评论,其余的从那里开始看起来有些不愉快。

回答by Quentin

You can't. --both starts and terminates a comment. This makes nesting them impossible.

你不能。--两者都开始和终止评论。这使得嵌套它们变得不可能。

回答by Philip Beck

Notepad++ together with the plugin XML Tools can do this.

Notepad++ 和插件 XML Tools 可以做到这一点。

Select a block of xml and on the xml tools submenu selected "Comment Selection".

选择一个 xml 块并在 xml 工具子菜单上选择“评论选择”。

Each existing "inner xml comment" will be altered so that it looks like this

每个现有的“内部 xml 注释”都将被更改,使其看起来像这样

  <!{1}** inner xml comment **{1}>

and if you add another outer comment in this way, those original inner comments will be further altered to

如果您以这种方式添加另一个外部评论,则这些原始内部评论将进一步更改为

  <!{2}** inner xml comment **{2}>