XML Getting Started Tutorial: XMLCDATA

Source: Internet
Author: User
The text in all XML documents will be parsed by the parser. Only the text in CDATA section (CDATAsection) is ignored by the parser. ParsedDataXML parser parses all the text in the XML document. When an XML element is parsed

The text in all XML documents will be parsed by the parser.

Only the text in the CDATA section is ignored by the parser.

Parsed Data

The XML parser parses all the text in the XML document.

When an XML element is parsed, the text between tags is also parsed:

This article will also be parsed

The parser does this because the XML element can contain other elements, as in this example The element contains two other elements (first and last ):

Bill Gates

The parser will break it into sub-elements like this:

Reference content is as follows:

Bill
Gates


Escape characters

Invalid XML characters must be replaced with entity reference ).

If you place a character in an XML document, such as "<", this document produces an error because the parser interprets it as the beginning of a new element. Therefore, you cannot write as follows:

If salary <1000 then

To avoid this error, replace the character "<" with the object reference, as shown in the following figure:

If salary <1000 then

There are 5 predefined entity references in XML:

<Less

> Greater

& And number

''Ellipsis

"" Quotation marks

Note: Strictly speaking, it is invalid to have only the characters "<" and "&" in XML. Ellipsis, quotation marks, and greater than signs are valid, but it is a good habit to replace them with entity references.

CDATA

Everything inside CDATA is ignored by the parser.

Assume that your text contains a large number of "<" and "&" characters-just as often occurs in programming code-then this XML element can be defined as a CDATA.

CDATA section starts"",结束于"":

Reference content is as follows:
Script
<br />function matchwo(a,b)<br />{<br />if (a < b && a < 0) then<br />&nbsp;&nbsp; {<br />&nbsp;&nbsp; return 1<br />&nbsp;&nbsp; }<br />else<br />&nbsp;&nbsp; {<br />&nbsp;&nbsp; return 0<br />&nbsp;&nbsp; }<br />}<br />
Script


In the preceding example, everything in the CDATA section is ignored by the parser.

CDATA section comment:

CDATA segments cannot contain strings "]>". Therefore, CDATA segments cannot be embedded.

At the same time, make sure that there are no spaces or lines in 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.