什么是CDATA和它做什么?
问题描述:
我有时会注意到包含<![CDATA [
和]]>
标签。我找不到任何解释。 CDATA是什么?为什么某些人使用它,需要什么?
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?
答
它告诉解释器它不应该尝试解释标签中包含的数据。例如,如果您想让XML文件包含带<或>,则XML解释器将该文件报告为无效,和>不会是标准标记的一部分。你只需要用CDATA标签包围代码。
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.