XML Guide--xml CDATA

Source: Internet
Author: User
Tags cdata contains return xml cdata xml parser
Xml

All text in an XML document will be parsed by the parser.

Only text within a CDATA part is ignored by the parser.

Parsing data

XML parsers typically process all the text in an XML document.

When an XML element is parsed, the text inside the XML element is also parsed:

<message>this text is also parsed</message>

The reason the XML parser does this is that the XML element may also contain other elements, as in the following example, the name element contains the first and last two elements internally:

<name><first>Bill</first><last>Gates</last></name>

The parser would consider the above code to be like this:

<name><first>Bill</first><last>Gates</last></name>

Escape character

An illegal XML character must be replaced with the corresponding entity.

If you use a character similar to "<" in an XML document, the parser will get an error because the parser will think that this is the beginning of a new element. So you should not write the code as follows:

<message>if Salary < 1000 then</message>

To avoid this, you must convert the character "<" to an entity, as follows:

<message>if Salary < 1000 then</message>

Here are five entities that are predefined in an XML document:

<< less than sign >> greater than && and ' single quotes ' double quotes
The entity must begin with the symbol "&" with the symbol ";" End.

Note: Only the "<" and "&" characters are strictly prohibited for XML. The rest is legal, and in order to reduce errors, using entities is a good habit.

CDATA Parts

All content within 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 part.

A CDATA part with "<! The [cdata["Mark begins with the"]]> "tag, ending with:

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

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

CDATA Considerations:

CDATA Parts can no longer contain CDATA parts (cannot be nested). If the CDATA part contains the character "]]>" or "<! [cdata[], there will be very likely to go wrong oh.

Also note that there are no spaces or line breaks between the string "]]>".



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.