Character name |
Character |
Entity reference |
And |
& |
& Amp; |
Yu no. |
> |
& Gt; |
Yu no. |
< |
& Lt; |
Single quotes |
' |
& Apos; |
Double quotation marks |
" |
& Quot; |
In XML documents, the characters that constitute element content or attributes are generally expressed in itself, but they are not applicable to reserved characters such as <"and"> "in XML. If you want to use reserved characters in XML documents, you must use the entity reference method to represent them. The table above lists the five reserved characters and entity references in XML.
For example, the object reference instance is named exa. xml.
<? XML version = "1.0" encoding = "gb2312"?>
<Recommendation>
<Title>& Lt;Romance of Three Kingdoms& Gt; & amp; & lt;Water Margin& Gt;</Title>
</Recommendation>
Result:
Entity reference solves how to use XML reserved characters in element values or attribute values. However, when a large number of reserved characters are used in an XML document, it is complicated to use entity references for processing, and the code readability is also reduced, marking with CDATA is a better solution. CDATA is marked as "<! [CDATA ["starts with"]> ". xml reserved characters can be directly used for the content between CDATA tags without being referenced by entities. Similarly, the above question is changed to use the CDATA mark.
Example: Use of CDATA, code. xml.
<? XML version = "1.0" encoding = "gb2312"?>
<Recommendation>
<Title>
<! [CDATA [<Romance of the Three Kingdoms> & <Water Margin>]>
</Title>
</Recommendation>