开发者

When do I need to use the " in xml?

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?

Exhibit A

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

Exhibit B

<boat>
    <name> Bertha </name>
    <description> Good boat.  10 feet long.  &开发者_如何学JAVA;quot;Fixer-upper&quot;</description>
</boat>


Both of your examples are valid.

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


From MSDN:

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


Both are correct and valid XML.

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


like this is ok <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>

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜