What is it?

Source: Internet
Author: User
Tags xml parser
ArticleDirectory
    • There are 5 predefined entity references in XML:

When I was working on a project today, I always reported an error when I wrote Js in the file. Later I found that it was in JS. The solution was to put Js in the file! [CDATA []>. Now let's take a look.<! [CDATA []> what is it.

The following content is transferred from: http://www.w3school.com.cn/xml/xml_cdata.asp

 

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

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

Pcdata

Pcdata indicatesResolved character data(Parsed character 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:

 
<Message> this article will also be parsed </message>

In this example, the <Name> element contains two other elements (first and last ):

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

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

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

Invalid xml characters must be replaced with entity reference ).

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

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

To avoid such errors, replace the character "<" with the entity reference, as shown in the following figure:

 
<Message> If salary <1000 then </message>
There are 5 predefined entity references in XML:
& Lt; < Less
& Gt; > Greater
& Amp; & And number
& Apos; ' Ellipsis
& Quot; " 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

The term CDATA refers to text data that should not be parsed by the XML Parser (unparsed character data ).

"<" And "&" are invalid in XML elements.

"<" Produces an error because the parser interprets the character as the beginning of the new element.

"&" Also produces errors because the parser interprets the character as the beginning of the character entity.

Some text, such as JavaScriptCode, Contains a large number of "<" or "&" characters. To avoid errors, you can define the script code as CDATA.

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

CDATA is partly composed"<! [CDATA ["Start,"]>"End:

 
<SCRIPT> <! [CDATA [function matchwo (a, B) {if (a <B & A <0) Then {return 1 ;}else {return 0 ;}]]> </SCRIPT>

In the preceding example, the parser ignores all content in the CDATA section.

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.