Role of XML CDATA

Source: Internet
Author: User
Tags xml cdata xml parser

When you use flash and XML for website applications Program For example, when you study the game rankings, people can enter some symbols when they enter their names freely, for example: "<", "> ","/","? When the XML is generated, the XML structure is broken and data is interrupted.

This requires the use of XML CDATA

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

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

--------------------------------------------------------------------------------

Parse data
The XML Parser usually processes all text in the 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 XML parser does this because the XML element may also contain other elements. In the following example, the name element contains the first and last elements:

<Name> <first> Bill </first> <last> Gates </last> </Name>

The parser will consider the aboveCodeYes:

<Name>
<First> Bill </first>
<Last> Gates </last>
</Name>

--------------------------------------------------------------------------------

Escape characters
Invalid xml characters must be replaced with corresponding entities.

If you use a character similar to "<" in the XML document, the parser will encounter an error because the parser considers this as the beginning of a new element. Therefore, the Code should not be written as follows:

<Message> If salary <1000 then </message>

To avoid this situation, you must convert the character "<" to an object, as shown below:

<Message> If salary <1000 then </message>

The following are five pre-defined entities in the XML document:

& Lt; <Yu no.
& Gt;> greater
& Amp; & and
& Apos; 'single quotes
& Quot; "Double quotation marks

The object must start with the symbol "&" and end with the symbol.
Note: Only the "<" and "&" characters are strictly forbidden for XML. The rest are legal. It is a good habit to use entities to reduce errors.

--------------------------------------------------------------------------------

CDATA parts
All content in CDATA is ignored by the parser.

If the text contains many "<" characters and "&" characters-like program code, it is best to put them in the CDATA component.

A CDATA part starts with "<! [CDATA ["Mark start, end with"]> "mark:

<SCRIPT>
<! [CDATA [
Function matchwo (A, B)
{
If (A <B & A <0) then
{
Return 1
}
Else
{
Return 0
}
}
]>
</SCRIPT>

In the previous example, all texts between CDATA components are ignored by the parser.

CDATA considerations:
CDATA components cannot be nested ). If the CDATA part contains the character "]>" or "<! [CDATA [", which may cause errors.

Note that there is no space or line break 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.