我什么时候需要使用 " 在 xml 中?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5186179/
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 14:35:30  来源:igfitidea点击:

When do I need to use the " in xml?

xml

提问by sixtyfootersdude

When I have quotes that are not in an attribute do I need to encode them using "?

当我有不在属性中的引号时,我需要使用 对它们进行编码"吗?

Which is correct? Exhibit A or Exhibit B?

哪个是正确的?图A还是图B?

Exhibit A

附件 A

<boat>
    <name> Bertha </name>
    <description> Good boat.  10 feet long.  "Fixer-upper"</description>
</boat>

Exhibit B

附件 B

<boat>
    <name> Bertha </name>
    <description> Good boat.  10 feet long.  &quot;Fixer-upper&quot;</description>
</boat>

回答by SLaks

Both of your examples are valid.

你的两个例子都是有效的。

You only need &quot;inside an attribute value; a "character would close the attribute early.

你只需要&quot;在一个属性值里面;一个"字符会早早关闭属性。

回答by chiper

From MSDN:

MSDN

&quot;must be used for an attribute value, but a straight quotation mark (") is acceptable as the content of an element.

&quot;必须用于属性值,但可以接受直引号 (") 作为元素的内容。

回答by chuan

like this is ok <boat description = " Good boat. 10 feet long. &quot;Fixer-upper&quot;"></boat>

这样就可以了 <boat description = " Good boat. 10 feet long. &quot;Fixer-upper&quot;"></boat>

like this is not ok <boat description = " Good boat. 10 feet long. "Fixer-upper""></boat>

这样不行 <boat description = " Good boat. 10 feet long. "Fixer-upper""></boat>

回答by Oded

Both are correct and valid XML.

两者都是正确且有效的 XML。

There is no need to use &quote;within text nodes.

无需&quote;在文本节点内使用。