Xml Cdata
# XML CDATA
* * *
All text in an XML document is parsed by the parser.
Only text within CDATA sections is ignored by the parser.
* * *
## PCDATA - Parsed Character Data
The XML parser usually parses all text in an XML document.
When an XML element is parsed, the text between its tags is also parsed:
This text is also parsed
The parser does this because XML elements can contain other elements, just like in this example, where the element contains two other elements (first and last):
BillGates
And the parser breaks it down into sub-elements like this:
Bill
Gates
Parsed character data (PCDATA) is a term used for text data that the XML parser parses.
* * *
## CDATA - (Unparsed) Character Data
The term CDATA refers to text data that should not be parsed by the XML parser.
Characters like "<" and "&" are illegal in XML elements.
"<" would cause an error because the parser would interpret it as the start of a new element.
"&" would cause an error because the parser would interpret it as the start of a character entity.
Some texts, such as JavaScript code, contain many "<" 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[
function matchwo(a,b)
{
if (a < b && a
In the above example, the parser ignores everything inside the CDATA section.
**Notes about CDATA sections:**
CDATA sections cannot contain the string "]]>". Nested CDATA sections are also not allowed.
The "]]>" that marks the end of a CDATA section must not contain spaces or line breaks.
YouTip