XML Guide - XML ​​CDATA

黄舟
Release: 2017-02-11 15:32:39
Original
1811 people have browsed it


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>
Copy after login

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>
Copy after login

The parser will think that the above code is like this:

<name> 
<first>Bill</first> 
<last>Gates</last> 
</name>
Copy after login



---------------------------------- -----------------------------------------------

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>
Copy after login
Copy after login

To avoid this situation, the characters "<" must be converted into entities, like the following:

<message>if salary < 1000 then</message>
Copy after login
Copy after login

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>
Copy after login


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)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template