<![CDATA []]>是什么?在XML是什么意思? [英] What does <![CDATA[]]> in XML mean?
问题描述
我经常在 XML
文件中找到这个奇怪的 CDATA
标记:
I often find this strange CDATA
tag in XML
files:
<![CDATA[some stuff]]>
我注意到,这个 CDATA
标记始终
I have observed that this CDATA
tag always comes at the beginning, and then followed by some stuff.
但有时会使用,有时却没有。我认为这是要标记一些东西
是将在其后插入的数据。但是一些东西
是什么样的数据?我用XML标签写的东西不是某种数据吗?
But sometimes it is used, sometimes it is not. I assume it is to mark that some stuff
is the "data" that will be inserted after that. But what kind of data is some stuff
? Isn't anything I write in XML tags some sort of data?
推荐答案
CDATA 代表字符数据,这意味着这些字符串之间的数据包含可以解释为XML标记的数据,但不应如此。
CDATA stands for Character Data and it means that the data in between these strings includes data that could be interpreted as XML markup, but should not be.
CDATA和注释之间的主要区别是:
The key differences between CDATA and comments are:
- As Richard points out, CDATA is still part of the document, while a comment is not.
- In CDATA you cannot include the string
]]>
(CDEnd
), while in a comment--
is invalid. - Parameter Entity references are not recognized inside of comments.
这意味着给了这四个
<!ENTITY MyParamEntity "Has been expanded">
<!--
Within this comment I can use ]]>
and other reserved characters like <
&, ', and ", but %MyParamEntity; will not be expanded
(if I retrieve the text of this node it will contain
%MyParamEntity; and not "Has been expanded")
and I can't place two dashes next to each other.
-->
<![CDATA[
Within this Character Data block I can
use double dashes as much as I want (along with <, &, ', and ")
*and* %MyParamEntity; will be expanded to the text
"Has been expanded" ... however, I can't use
the CEND sequence. If I need to use CEND I must escape one of the
brackets or the greater-than sign using concatenated CDATA sections.
]]>
<description>An example of escaped CENDs</description>
<!-- This text contains a CEND ]]> -->
<!-- In this first case we put the ]] at the end of the first CDATA block
and the > in the second CDATA block -->
<data><![CDATA[This text contains a CEND ]]]]><![CDATA[>]]></data>
<!-- In this second case we put a ] at the end of the first CDATA block
and the ]> in the second CDATA block -->
<alternative><![CDATA[This text contains a CEND ]]]><![CDATA[]>]]></alternative>
这篇关于<![CDATA []]>是什么?在XML是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!