<message>This text is also parsed</message>
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):
<name><first>Bill</first><last>Gates</last></name>
And the parser will break it into sub-elements like this:
<name><first>Bill</first><last>Gates</last></name>
Parsed Character Data (PCDATA) is a term used for text data parsed by an XML parser.
The term CDATA is text data that should not be parsed by XML parsers.
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 in the CDATA section is ignored by the parser.
The CDATA part starts with " <![CDATA[ " and ends with " ]]> ":
<script><![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 section:
The CDATA section cannot contain the string "]]>". Nested CDATA sections are also not allowed.
The "]]>" marking the end of the CDATA section cannot contain spaces or newlines.
The comments in the CDATA section above are the rules of XML CDATA that you need to follow!
In the next section, we will explain XML encoding.