在 XML 中存储引用数据的可接受方式是什么? [英] What's the accepted way of storing quoted data in XML?

查看:62
本文介绍了在 XML 中存储引用数据的可接受方式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 XML 中存储引用数据的可接受方式是什么?

例如,对于一个节点,哪个是正确的?

  • (a) <name>Jesse "The Body" Ventura</name>
  • (b) <name>Jesse \"The Body\" Ventura</name>
  • (c) Jesse &quot;The Body&quot;文图拉
  • (d) 以上都不是(请说明)

如果(a),你对属性做了什么?如果 (c),混合 HTML & 真的合适吗?XML?同样,你如何处理单引号和花括号?

解决方案

您的正确答案是 A &C 作为 " 不是必须在元素数据中编码的字符.

您应该始终是 XML 编码字符,例如 ><& 以确保您没有如果它们不在 CDATA 部分内,则会出现问题.这些是元素数据需要关注的关键项目.

在谈论属性时,您还必须注意属性值内部的 '",具体取决于用于包围值的符号类型.>

我发现经常对 "' 进行编码在各个方面都是一个更好的主意,因为它有时在转换为其他格式时会有所帮助,其中 "' 也可能导致问题.

What's the accepted way of storing quoted data in XML?

For example, for a node, which is correct?

  • (a) <name>Jesse "The Body" Ventura</name>
  • (b) <name>Jesse \"The Body\" Ventura</name>
  • (c) <name>Jesse &quot;The Body&quot; Ventura</name>
  • (d) none of the above (please specify)

If (a), what do you do for attributes? If (c), is it really appropriate to mix HTML & XML? Similarly, how do you handle single and curly quotes?

解决方案

Your correct answer is A & C as the " is not a character that must be encoded in element data.

You should always be XML encoding characters such as >, <, and & to ensure that you don't have issues if they are NOT inside a CDATA section. These are key items to be concerned about for element data.

When talking about attributes you have to then also be careful of ' and " inside attribute values depending on the type of symbol you use to surround the value.

I've found that often encoding " and ' is a better idea in all aspects as it helps at times when converting to other formats, where the " or ' might cause problems there as well.

这篇关于在 XML 中存储引用数据的可接受方式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆