I have seen in many XML file has the data inside this <![CDATA[ ]]>. What is the use of this?
From Wikipedia
A CDATA section starts with the following sequence:
<![CDATA[
and ends with the first occurrence of the sequence:
]]>
All characters enclosed between these two sequences are interpreted as characters, not markup or entity references. For example, in a line like this:
<sender>John Smith</sender>
the opening and closing "sender" tags are interpreted as markup. However, if written like this:
<![CDATA[<sender>John Smith</sender>]]>
then the code is interpreted the same as if it had been written like this:
<sender>John Smith</sender>
Check out the Wiki page for more details.
See CDATA at Wikipedia:
In an XML document or external parsed entity, a CDATA section is a section of element content that is marked for the parser to interpret as only character data, not markup.
That means the parser will not interpret any data contained in <![CDATA[ ]]>.
Lets say you want to store HTML as text in an XML document. This is wrong:
<root>
<myhtml>
<div><b>Foo bar</b></div>
</myhtml>
</root>
The parser would try to parse <div><b>Foo bar</b></div> and create DOM elements. It would work in this example, but not for documents that conform to an DTD.
Instead, we want this:
<root>
<myhtml>
<![CDATA[ <div><b>Foo bar</b></div> ]]>
</myhtml>
</root>
and <div><b>Foo bar</b></div> will become the content of a text node.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With