CDATA的含义是什么

时间:2022-07-01 01:49:53

Gurus,

大师,

I am self taught. There's a lot of what you enlightened ones call basic I know nothing about.

我自学。有很多你们这些开明的人称之为基础的东西我一无所知。

Reading this jQuery Tutorial, I noticed this tag (for lack of better word): "CDATA" as shown here (third line from the top):

在阅读jQuery教程时,我注意到这个标签(因为没有更好的词):“CDATA”,如下所示(从顶部的第三行):

<script src="http://jquery.com/src/jquery-latest.js"></script>
<script> 
//<![CDATA[    
$(document).ready(function(){
$(".article .thebody").hide();
$("#container .article ul")
       .prepend("<li class='readbody'><a href='' title='Read the article'>Read Body</a></li>");

$(".actions li.readbody a").click(function(event){
$(this).parents("ul").prev(".thebody").toggle();
event.preventDefault();
     });
   });
//]]></script>

What is the meaning of CDATA? Are there tags similar to CDATA?

CDATA的含义是什么?是否有类似于CDATA的标签?

5 个解决方案

#1


15  

With <![CDATA[ you can embed JS in XML (and XHTML) documents without the need to replace special XML characters like <, >, &, etc by XML entities &lt;, &gt;, &amp; etc to prevent that the XML syntax get malformed and that you get errors like The entity name must immediately follow the '&' in the entity reference. The general recommendation is however to put JS code in its own .js file which you then include by a <script src>.

在< ![CDATA]您可以在XML(和XHTML)文档中嵌入JS,而不需要用XML实体< > &amp替换<、>等特殊的XML字符为了防止XML语法出现错误,以及出现实体名称之类的错误,必须立即跟随实体引用中的'&'。但是,一般的建议是将JS代码放在它自己的. JS文件中,然后将其包含在

The <![CDATA[ is not needed in plain HTML documents. Unless you're developing with a XML based view technology like Facelets (for JSF) or ASP.NET MVC, there's absolutely no need to declare your HTML as XHTML. Just a <!DOCTYPE html> would suffice

< !在普通的HTML文档中不需要使用CDATA。除非您正在开发基于XML的视图技术,如Facelets(用于JSF)或ASP。NET MVC,完全不需要将HTML声明为XHTML。只是一个< !DOCTYPE html >就足够了

#2


3  

The reason for CDATA in this scenario is to allow the document to be loaded as straight XML. In XML the // will be treated as text instead of a comment and hence it will then see CDATA as an XML tag.

在此场景中,CDATA的原因是允许将文档作为直接XML加载。在XML中,//将被视为文本而不是注释,因此它将把CDATA视为XML标记。

#3


3  

Wikipedia sums it up really well:

*总结得很好:

In an XML document or external parsed entity, a CDATA section is a section of element content that is marked for the parser to interpret as only character data, not markup. A CDATA section is merely an alternative syntax for expressing character data; there is no semantic difference between character data that manifests as a CDATA section and character data that manifests as in the usual syntax in which < and & would be represented by &lt; and &amp;, respectively.

在XML文档或外部解析实体中,CDATA部分是元素内容的一部分,标记为供解析器解释为字符数据,而不是标记。CDATA部分只是表示字符数据的一种替代语法;以CDATA部分表示的字符数据和以&lt表示的通常语法表示的字符数据之间没有语义差异;和和,分别。

The way I look at it, CDATA keeps the XML parser from sterilizing your code (making it display as just text, not code).

按照我的看法,CDATA使XML解析器不会对代码进行消毒(使其仅显示为文本,而不是代码)。

I hope that explains some of it...

我希望这能解释其中的一些……

#4


2  

CDATA is character data which is ignored by the validator.

CDATA是被验证器忽略的字符数据。

You wrap things like javascript in CDATA tags so the your html validates (of course this is uncessary if you follow the more recent XHTML standards).

在CDATA标记中包装javascript这样的东西,以便html验证(当然,如果遵循最新的XHTML标准,这是不需要的)。

#5


1  

This is a special sequence to allow inline javascript with special characters while still allowing the page to pass as valid xhtml. More details here. Essentially, don't worry about its exact meaning, but do put it in there!

这是一个特殊的序列,允许带有特殊字符的内联javascript,同时仍然允许页面作为有效的xhtml传递。更多细节在这里。本质上,不要担心它的确切含义,但一定要把它放在那里!

#1


15  

With <![CDATA[ you can embed JS in XML (and XHTML) documents without the need to replace special XML characters like <, >, &, etc by XML entities &lt;, &gt;, &amp; etc to prevent that the XML syntax get malformed and that you get errors like The entity name must immediately follow the '&' in the entity reference. The general recommendation is however to put JS code in its own .js file which you then include by a <script src>.

在< ![CDATA]您可以在XML(和XHTML)文档中嵌入JS,而不需要用XML实体< > &amp替换<、>等特殊的XML字符为了防止XML语法出现错误,以及出现实体名称之类的错误,必须立即跟随实体引用中的'&'。但是,一般的建议是将JS代码放在它自己的. JS文件中,然后将其包含在

The <![CDATA[ is not needed in plain HTML documents. Unless you're developing with a XML based view technology like Facelets (for JSF) or ASP.NET MVC, there's absolutely no need to declare your HTML as XHTML. Just a <!DOCTYPE html> would suffice

< !在普通的HTML文档中不需要使用CDATA。除非您正在开发基于XML的视图技术,如Facelets(用于JSF)或ASP。NET MVC,完全不需要将HTML声明为XHTML。只是一个< !DOCTYPE html >就足够了

#2


3  

The reason for CDATA in this scenario is to allow the document to be loaded as straight XML. In XML the // will be treated as text instead of a comment and hence it will then see CDATA as an XML tag.

在此场景中,CDATA的原因是允许将文档作为直接XML加载。在XML中,//将被视为文本而不是注释,因此它将把CDATA视为XML标记。

#3


3  

Wikipedia sums it up really well:

*总结得很好:

In an XML document or external parsed entity, a CDATA section is a section of element content that is marked for the parser to interpret as only character data, not markup. A CDATA section is merely an alternative syntax for expressing character data; there is no semantic difference between character data that manifests as a CDATA section and character data that manifests as in the usual syntax in which < and & would be represented by &lt; and &amp;, respectively.

在XML文档或外部解析实体中,CDATA部分是元素内容的一部分,标记为供解析器解释为字符数据,而不是标记。CDATA部分只是表示字符数据的一种替代语法;以CDATA部分表示的字符数据和以&lt表示的通常语法表示的字符数据之间没有语义差异;和和,分别。

The way I look at it, CDATA keeps the XML parser from sterilizing your code (making it display as just text, not code).

按照我的看法,CDATA使XML解析器不会对代码进行消毒(使其仅显示为文本,而不是代码)。

I hope that explains some of it...

我希望这能解释其中的一些……

#4


2  

CDATA is character data which is ignored by the validator.

CDATA是被验证器忽略的字符数据。

You wrap things like javascript in CDATA tags so the your html validates (of course this is uncessary if you follow the more recent XHTML standards).

在CDATA标记中包装javascript这样的东西,以便html验证(当然,如果遵循最新的XHTML标准,这是不需要的)。

#5


1  

This is a special sequence to allow inline javascript with special characters while still allowing the page to pass as valid xhtml. More details here. Essentially, don't worry about its exact meaning, but do put it in there!

这是一个特殊的序列,允许带有特殊字符的内联javascript,同时仍然允许页面作为有效的xhtml传递。更多细节在这里。本质上,不要担心它的确切含义,但一定要把它放在那里!