All text in the XML document will be parsed by the parser.
Only text within the CDATA component will be ignored by the parser.
---------------------------------------- ---------------------------------------
Analytical data
XML parsers typically process all text in an XML document.
When the XML element is parsed, the text inside the XML element will also be parsed:
<message>This text is also parsed</message>
The reason why the XML parser does this is that there may be other text inside the XML element. Contains other elements, like the example below, the name element contains two elements: first and last:
<name><first>Bill</first><last>Gates</last></name>
The parser will think that the above code is like this:
<name> <first>Bill</first> <last>Gates</last> </name>
---------------------------------- -----------------------------------------------
Escape characters
Illegal XML characters must be replaced with corresponding entities.
If you use characters like "<" in an XML document, the parser will cause an error because the parser will think that this is the beginning of a new element. So the code should not be written like the following:
<message>if salary < 1000 then</message>
To avoid this situation, the characters "<" must be converted into entities, like the following:
<message>if salary < 1000 then</message>
The following are five predefined entities in XML documents:
< < Less than sign
> > Greater than sign
& & and
' ' Single quotation mark
" " Double quotation mark
The entity must start with the symbol "&" and end with the symbol ";".
Note: Only the "<" character and the "&" character are strictly prohibited for XML. The rest is legal, and it's a good practice to use entities to reduce errors.
---------------------------------------- ---------------------------------------
CDATAComponent
Everything inside CDATA will be ignored by the parser.
If the text contains a lot of "<" characters and "&" characters - just like program code, then it is best to put them all in the CDATA component.
A CDATA component starts with the "" tag:
<script> <![CDATA[ function matchwo(a,b) { if (a < b && a < 0) then { return 1 } else { return 0 } } ]]> </script>
In front of In this example, all text between CDATA components will be ignored by the parser.
CDATA Notes:
CDATA components can no longer contain CDATA components (cannot be nested). If the CDATA component contains the characters "]]>" or "
Also note that there are no spaces or newlines between the strings "]]>".
The above is the content of XML Guide-XML CDATA. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!