Ma leian tihti seda kummalist CDATA
sildi XML
failides:
<![CDATA[some stuff]]>
Olen täheldanud, et see CDATA
silt on alati alguses ja siis järgneb sellele mingi kraam.
Aga vahel kasutatakse seda, vahel mitte. Ma eeldan, et see on selleks, et märkida, et jumba
on "andmed", mis lisatakse pärast seda. Aga millised andmed on some stuff
? Kas mitte kõik, mida ma kirjutan XML-tähega, ei ole mingi andmestik?
CDATA tähendab Character Data ja see tähendab, et nende stringide vahel olevad andmed sisaldavad andmeid, mida võiks tõlgendada XML-märgistusena, kuid mida ei tohiks tõlgendada.
Peamised erinevused CDATA ja kommentaaride vahel on järgmised:
]]>
(CDEnd
), samas kui kommentaaris --
on kehtetu.See tähendab, et antud need kolm XML-lõiku ühest hästi vormistatud dokumendist:
<!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>