May 27, 2021 XML
This section is about XML CDATA, which refers to character data, which we define as blocks of text.
All text in the XML document is parsed by the parser.
Only the text in the CDATA segment is ignored by the parser.
XML parsers typically parse all the text in an XML document.
When an XML element is parsed, the text between its labels is also parsed:
<message>This text is also parsed</message>
The parser does this because the XML element can contain other elements, just as in this instance, where the element contains two other elements (first and last):
<name><first>Bill</first><last>Gates</last></name>
The parser breaks it down into child elements like this:
<name>
<first>Bill</first>
<last>Gates</last>
</name>
Parsing character data (PCDATA) is a term used by XML parsers to parse text data.
The term CDATA is text data that should not be parsed by an XML parser.
Characters such as ""
An error occurs because the parser interprets the character as the beginning of the new element.
An error occurs because the parser interprets the character as the beginning of the character entity.
Some text, such as JavaScript code, contains a large number of "" To avoid errors, you can define the script code as CDATA.
Everything in the CDATA section is ignored by the parser.
CDATA is partly composed of the " slt;! CDATA " starts, ends with "
<script>
<![CDATA[
function matchwo(a,b)
{
if (a < b && a < 0) then
{
return 1;
}
else
{
return 0;
}
}
]]>
</script>
In the example above, 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.
Mark the ""
The comments in the CDATA section above are the rules you need to follow for XML CDATA!
In the next section, we'll cover XML coding.