XML Tutorial/Introduction/CDATA

Материал из Web эксперт
Перейти к: навигация, поиск

CDATA sections can tell the XML parser not to parse the text.

   <source lang="xml">

CDATA sections look like this: <comparison><![CDATA[6 is < 7 & 7 > 6]]></comparison> Everything starting after the <![CDATA[ and ending at the ]]> is ignored by the parser. The following example uses a CDATA section to keep an XML parser from parsing a section of JavaScript: <script language="JavaScript"><![CDATA[ function myFunc() {

   if(0 < 1 && 1 < 2) 
       alert("Hello"); 

} ]]></script></source>


Displaying Elements as Text

   <source lang="xml">

You may not nest CDATA sections. To write ]]> and you are not closing a CDATA section, the > must be written as >. <xml_book>

 <tags>
   <appearance>
     <![CDATA[

<animal>

 <name language="Latin">T2</name>
 <project>project1</project>
 <weight>3 points</weight>

</animal> ]]>

   </appearance>
 </tags>

</xml_book></source>