What is XML CDATA?

Source: Internet
Author: User
Tags cdata xml cdata xml 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, the character "<" must be converted to an entity, as follows:

<message>if Salary &lt; 1000 then</message>


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

&lt; < Less than sign
&gt; > Greater-than sign
&amp; & And
&apos; ' Single quotation mark
&quot; " 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:

A CDATA Part cannot be included between 1.CDATA parts (cannot be nested). If the CDATA part contains the character "]]>" or "<! [cdata[], there will be very likely to go wrong oh.

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

<! [What do you mean by cdata[]]>???

Marked as plain text, without which the < > & characters cannot be stored directly in XML and need to be escaped, but with this tag they are not required to be escaped and stored in an XML document.
You can avoid unexpected special symbols that cause XML parsing errors.

I was just beginning to learn something about XML, where I encountered a segment called CDATA. The explanation here is that everything inside CDATA is ignored by the parser. I don't know what that means. In simple terms, it's CDATA when to use it, what's in it. If you use this, what will be the result.
There is also validation of XML validation. What is the meaning of this, why to verify the effectiveness of the general how to verify it, how the method. I read that there are two methods of DTD and XML schema, how to use, what is the difference.
The problem is a bit more, but it's two major problems. Want to know the heroes help younger brother, with a simple little words to tell me. Thank you very much.
==================================================

When you use Flash and XML to make Web applications, such as allowing people to enter their names freely, people can enter symbols such as "<", ">", "/". "And so on, when XML is generated, it destroys the XML structure and interrupts the data.

This is going to be in XML CDATA

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

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

 

<![ What is the meaning of cdata[]]>. ~
read data from database generate XML file, add a "<![ cdata[   ]]> "What does it mean.
Response.Write "<body><! [Cdata[
Response.Write rs ("message")
Response.Write "]]></body>"
The
, is marked as plain text, without this <   >  & characters are not stored directly in XML and need to be escaped, and this tag is not required to be escaped and stored in an XML document. What is the difference between , pcdata and CDATA? 。

Pcdata represents the parsed character data.
CDATA is text that is not parsed through the parser, and the labels in the text are not treated as tokens.
CDATA Indicates what the inside data XML does not parse. For example, it might be the following paragraph.
<! [cdata[
if (a>b) {
System.out.println (a);
}

]]>

notice a ">" symbol above.


Pcdata data is to be parsed by the XML parser, the above > parsing is definitely going to go wrong, so use the entity definition. The above data, if used in Pcdata, is shown as follows:

if (a>b) {
System.out.println (a);
}



CDATA is a keyword used in an XML document to tell the browser that this part of the content does not need parsing, is for other programs, such as JavaScript, and so on, #PCDATA是在 XML constraint documents, such as DTD type constraint documents, In this case, the content of the element or the value range of the attribute, and so on, is a string form,

You can avoid unexpected special symbols that cause XML parsing errors.

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.