What is CDATA section in an xml document?

 Posted by Ddd on 2/13/2011 | Category: Web Services, Remoting Interview questions | Views: 4287 | Points: 40
Answer:

CDATA -
Unparsed Character Data
The term CDATA is used about text data that should not be parsed by the XML parser.
example:
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.

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 "]]>":
EXAMPLE:
<?xml version="1.0"?>
<catalog>
<book>
<bookname>ASP.NET</bookname>
</book>
<script>
<![CDATA[
function demo()
{
alert("hello");
}
]]>
</script>
</catalog>


Source: http://www.w3schools.com | Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response