XML CDATA
All text in the XML document will be parsed by the parser.
Only text in the CDATA section will be ignored by the parser.
PCDATA - Parsed character data
XML parsers typically parse all text in an XML document.
When an XML element is parsed, the text between its tags is also parsed:
The parser does this because XML elements can contain other elements, as in this example, where the <name> element contains two other elements ( first and last):
And the parser will break it into sub-elements like this:
<first>Bill</first>
<last>Gates</last>
</name>
Parsed Character Data (PCDATA) is a term used for text data parsed by an XML parser.
CDATA - (Unparsed) Character Data
The term CDATA is text data that should not be parsed by an XML parser.
Characters like "<" and "&" are illegal in XML elements.
"<" will generate an error because the parser will interpret this character as the beginning of a new element.
"&" will generate an error because the parser will interpret this character as the beginning of a character entity.
Some text, such as JavaScript code, contains a large number of "<" or "&" characters. To avoid errors, the script code can be defined as CDATA.
Everything within the CDATA section will be ignored by the parser.
The CDATA part starts with "<![CDATA[" and ends with "]]>":
<![CDATA[
function matchwo(a,b)
{
if (a < b && a < 0) then
{
return 1;
}
else
{
Return 0;
}
}
]]>
</script>
In the above example, the parser ignores everything in the CDATA section.
Notes on the CDATA part:
The CDATA part cannot contain the string "]]>". Nested CDATA sections are also not allowed.
The "]]>" marking the end of the CDATA section cannot contain spaces or newlines.