Are CDATA tags ever necessary in script tags and if so when?
In other words, when and where is this:
<script type="text/javascript"> //<![CDATA[ ...code... //]]> </script>
preferable to this:
<script type="text/javascript"> ...code... </script>
A CDATA section contains text that will NOT be parsed by a parser. Tags inside a CDATA section will NOT be treated as markup and entities will not be expanded. The primary purpose is for including material such as XML fragments, without needing to escape all the delimiters.
HTMLWeb DevelopmentFront End Technology. The CDATA Section interface is used within XML for including extended portions of text. This text is unescaped text, like < and & symbols. These symbols do not want to escape.
Climate Data Analysis Tools (CDAT) helps in processing and visualization of climate model data. In the present study a modeling tool is developed by python programming language, for retrieving the climate grid point data. The retrieved data is clipped for specific area of interest using shapefile of the area.
CDATA stands for Character Data. You can use this to escape some characters which otherwise will be treated as regular XML. The data inside this will not be parsed. For example, if you want to pass a URL that contains & in it, you can use CDATA to do it.
A CDATA section is required if you need your document to parse as XML (e.g. when an XHTML page is interpreted as XML) and you want to be able to write literal i<10
and a && b
instead of i<10
and a && b
, as XHTML will parse the JavaScript code as parsed character data as opposed to character data by default. This is not an issue with scripts that are stored in external source files, but for any inline JavaScript in XHTML you will probably want to use a CDATA section.
Note that many XHTML pages were never intended to be parsed as XML in which case this will not be an issue.
For a good writeup on the subject, see https://web.archive.org/web/20140304083226/http://javascript.about.com/library/blxhtml.htm
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With