Dažnai randu šią keistą CDATA
žymą XML
failuose:
<![CDATA[some stuff]]>
Pastebėjau, kad ši CDATA
žyma visada yra pradžioje, o po jos seka kažkokia informacija.
Tačiau kartais ji naudojama, o kartais ne. Manau, kad ji skirta pažymėti, kad some stuff
yra "duomenys", kurie bus įterpti po to. Tačiau kokie duomenys yra kai kurie nors duomenys
? Argi viskas, ką rašau XML žymėmis, nėra tam tikros rūšies duomenys?
CDATA reiškia simbolių duomenys ir reiškia, kad tarp šių eilučių yra duomenys, kurie *galėtų būti interpretuojami kaip XML žymės, bet neturėtų būti interpretuojami.
Pagrindiniai CDATA ir komentarų skirtumai yra šie:
]]>
(CDEnd
), o į komentarą --
negalioja.Tai reiškia, kad pateikus šias tris XML fragmentus iš vieno gerai suformuoto dokumento:
<!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>
Jis naudojamas duomenims, kurie kitu atveju galėtų būti laikomi xml, nes juose yra tam tikrų simbolių, įrašyti.
Tokiu būdu viduje esantys duomenys bus rodomi, bet neinterpretuojami.