亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

<![CDATA[]>在XML中意味著什么?

<![CDATA[]>在XML中意味著什么?

繁花不似錦 2019-06-03 16:58:58
<![CDATA[]>在XML中意味著什么?我經常覺得這很奇怪CDATA標記入XML檔案:<![CDATA[some stuff]]>我注意到CDATA標簽總是出現在開頭,然后跟著一些東西。但有時它被使用,有時卻不是。我想是為了標記some stuff是在之后插入的“數據”。但是什么樣的數據是some stuff?我用XML標記寫的東西難道不是某種數據嗎?
查看完整描述

3 回答

?
慕村225694

TA貢獻1880條經驗 獲得超4個贊

CDATA代表字符數據這意味著這些字符串之間的數據包括被解釋為XML標記,但不應該解釋為XML標記。

CDATA與評論之間的主要區別是:

  • 理查德指出

    ,CDATA仍然是文檔的一部分,而注釋則不是。
  • 在CDATA中,不能包含字符串。

    ]]> (CDEnd

    ),而在評論中

    --無效.

  • 參數實體

    注釋內部不能識別引用。

這意味著從一個格式良好的文檔中獲得這三個XML片段:

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


查看完整回答
反對 回復 2019-06-03
?
開心每一天1111

TA貢獻1836條經驗 獲得超13個贊

一個很大的用例:您的XML包含一個程序,作為數據(例如,Java的網頁教程)。在這種情況下,您的數據包含大量字符,其中包括‘&’和‘<’,但是這些字符不應該是XML。

比較:

<example-code>while (x &lt; len &amp;&amp; !done) {
    print( &quot;Still working, &apos;zzz&apos;.&quot; );
    ++x;
    }</example-code>

帶著

<example-code><![CDATA[
while (x < len && !done) {
    print( "Still working, 'zzzz'." );
    ++x;
    }
]]></example-code>

特別是如果您正在從文件中復制/粘貼這段代碼(或者將其包括在預處理器中),那么在XML文件中只包含您想要的字符是很好的,w/o將它們與XML標記/屬性混為一談。正如@paary所提到的,其他常見用途包括嵌入包含符號的URL時。最后,即使數據只包含幾個特殊字符,但數據很長(比如說,一章的文本),在編輯XML文件時不必對這幾個實體進行編碼也很好。

(我懷疑所有與評論的比較都有點誤導/毫無幫助。)


查看完整回答
反對 回復 2019-06-03
  • 3 回答
  • 0 關注
  • 3241 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號