什么是 <![CDATA[]]>在 XML 中是什么意思? [英] What does <![CDATA[]]> in XML mean?

查看:34
本文介绍了什么是 <![CDATA[]]>在 XML 中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常在 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.

但有时使用,有时不使用.我假设它是标记 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.

这意味着从一个格式良好的文档中给出这四个 XML 片段:

This means given these four snippets of XML from one well-formed document:

<!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>

这篇关于什么是 &lt;![CDATA[]]&gt;在 XML 中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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