What exactly is CDATA and what does it do?

柔情痞子 提交于 2019-11-30 01:56:54

问题


I sometimes notice a CSS or JS code surrounded with <![CDATA[ and ]]> tags. I couldn't find any explanation to this. What does CDATA do? Why is it used by some people and what is it needed for?


回答1:


It tells the interpreter that it should not try to interpret the data enclosed in the tags. For example, if you want a XML file to contain a comment with < or >, XML interpreters will report the file as invalid because the caracters < and > will not be part of standard tag. You simply have to surround the code with the CDATA tags.




回答2:


It marks data that shouldn't be parsed - in most cases, just HTML or text that needs to be written directly to the page.

Further explanation: http://www.w3schools.com/xml/xml_cdata.asp




回答3:


Here's some info for you: http://en.wikipedia.org/wiki/CDATA

How you couldn't find anything on this is a mystery ;)




回答4:


When you write inline javascript or CSS in an HTML file (using the script and style tags), Those CDATA comments prevent things like the HTML validators from catching false positives when validating an HTML document.



来源:https://stackoverflow.com/questions/3813595/what-exactly-is-cdata-and-what-does-it-do

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!