问题描述
在 XML 中存储引用数据的可接受方式是什么?
例如,对于一个节点,哪个是正确的?
- (a) <name>Jesse "The Body" Ventura</name>
- (b) <name>Jesse \"The Body\" Ventura</name>
- (c)
- (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 "The Body" 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 中存储引用数据的可接受方式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!