CDATA 是否保留 XML 中的所有转义字符序列?
XML 解析器是否会翻译转义字符,例如 
和 

,即使它们出现在 CDATA 中?
我对这个问题的答案感到困惑: XML 规范是否规定解析器需要将 \n\r 始终转换为 \n,即使 \n\r 出现在 CDATA 部分中?
...因为它引用了规范说像 #xD #xA
这样的序列被替换为单个 '\n' 字符,但接着说使用 
和 

是保存字符的可靠方法。分号重要吗? (我没有时间研究 XML 规范)
此外,我知道上面的 2 个字符是回车符和换行符,并且它们被 XML 解析器规范化为换行符 - 如果内部发生的规则换行符的 CDATA 与一般的转义序列不同,那么我特此问这两个问题!
谢谢, RP
Do XML parsers translate escaped characters such as
and
even when they occur in CDATA?
I was confused by the answer to this question: Does the XML specification states that parser need to convert \n\r to \n always, even when \n\r appears in a CDATA section?
...because it quotes from the spec saying that sequences like #xD #xA
are replaced with a single '\n' character, but then goes on to say that using
and
is a reliable way to preserve the characters. Is the semi-colon significant? (I don't have time to study the XML spec)
Also, I am aware that the 2 characters above are carriage return and line feed, and that they are normalized to just line feed by XML parsers - if the rules for what happens inside CDATA for line breaks is different to escaped sequences in general, then I hereby ask both questions!
Thanks,
rp
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有。解析器不会触及 CDATA 部分中的任何内容。
分号没有什么区别。
Nope. The parser does not touch anything in a CDATA section.
The semicolon does not make a difference.