Five reserved characters and entity references in XML

Source: Internet
Author: User

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>

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.