简体   繁体   中英

CDATA - Used in XML and in Javascript

CDATA - 在 XML 和 Javascript 中使用,两者的含义是否相同,仅是一种注释?。

CDATA actually has two meanings in XML, connected to each other only by some obscure common ancestry in SGML.

It's one of the attribute types you can declare in a DTD - but if you're the kind of person who uses DTDs, then you probably wouldn't be asking this question.

More commonly, it's markup that can occur in the body of the document.

<a>Some <![CDATA[cdata text]]></a>

It's best to think of this as an alternative way of escaping special characters. If there aren't any special characters, as in this example, then it's equivalent to

<a>Some cdata text</a>

But with special characters:

<a>Some <![CDATA[cdata text & ampersands]]></a>

it's equivalent to

<a>Some cdata text &amp; ampersands</a>

Applications are supposed to treat these two as equivalent, but some APIs allow an application to see the difference, so you'll find some badly-written applications that work with one form and not the other.

The information contained in CDATA provide a way to tell the parser that there is no markup in the characters contained by the CDATA section.

Check these references here:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM