7 Years
Discussion Span
Last Post by svmvishnu

All text in an XML document will be parsed by the parser.But text inside a CDATA section will be ignored by the parser.

CDATA - (Unparsed) Character Data
The term CDATA is used about text data that should not be parsed by the XML parser.
Characters like "<" and "&" are illegal in XML elements.
"<" will generate an error because the parser interprets it as the start of a new element.
"&" will generate an error because the parser interprets it as the start of an character entity.
Some text, like JavaScript code, contains a lot of "<" or "&" characters.

To avoid errors script code can be defined as CDATA. Everything inside a CDATA section is ignored by the parser.
A CDATA section starts with "<![CDATA[" and ends with "]]>":[/B>]

function matchwo(a,b)
if (a < b && a < 0) then
  return 1;
  return 0;

In the example above, everything inside the CDATA section is ignored by the parser.

Notes on CDATA sections:
A CDATA section cannot contain the string "]]>". Nested CDATA sections are not allowed.
The "]]>" that marks the end of the CDATA section cannot contain spaces or line breaks.

Edited by rajarajan2017: n/a


CDATA is special mean in XML. XML has five special meta characters.
1. '(Single quotes)
2. "(Double quotes)
3. &
4. <
5. >

This meta characters may make confusion while parse the xml content in programming.i.e the parser some time treat < and > as element's characters.
For example

<SampleElement> This is special char < in XML </SampleElement>

In the above xml, the parser will read the <(which is in bold) symbol and treat as xml element and expect a name and closing element. This cause produce error,so to eliminate this kind of problem we put these kind of data in CDATA container. CDATA tells parser that following information on it is data not xml element. Simply CDATA will differentiate data and xml element.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.