[The escape character in the]xml file

Source: Internet
Author: User
Tags cdata

Original address: http://www.cnblogs.com/zhxhdean/archive/2012/02/08/2342498.html

If you use a character like "<" in an XML document, the parser will get anerror because the parser will assume that this is the beginning of a new element. Therefore, you should not write the code as follows:

<message>if Salary < Then</message>

To avoid this situation, the character "<" must be converted to an entity, as follows:

&lt; Then</message>

Here are five pre-defined entities in the XML document:

&LT; <
&GT; >
&amp; & and
&apos; single quotation mark
&quot;


The entity must begin with the symbol "&", with the symbol ";" End .

Note: only the "<" character and the "&" character are strictly forbidden for XML. The rest is legal, and the use of entities is a good habit in order to reduce errors.

CDATA Parts

All content inside CDATA is ignored by the parser.

If the text contains a lot of "<" characters and "&" characters-just like the program code-it's best to put them all in a CDATA widget.

A CDATA part to "<![ cdata["tag to start with"]]>"Mark end:

<script><![ Cdata[function Matchwo (b) {if (a < b && a < 0) Then{return 1}else{return 0}}]]></script> 

In the previous example, all the text between the CDATA parts is ignored by the parser.

CDATA Considerations:

CDATA Parts can no longer contain CDATA parts (not nested). If the CDATA part contains the character "]]>" or "<![ Cdata[", will be very likely to make mistakes oh.

Also note thatthere is no space or line break between the string "]]>".

[The escape character in the]xml file

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.