由Rails生成的HTML和CDATA [英] HTML and CDATA produced by Rails

查看:57
本文介绍了由Rails生成的HTML和CDATA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在试验一些Ruby on Rails JavaScript生成器

并看到我以前没有的东西。也许值得吗?


在下面的页面中,脚本包含在


//<![CDATA [

//]]>


这个技巧是否基于HTML和XHTML的任何真实信息?我认为他们想要实现的是一种生成脚本的方法

块,可以在HTML或XHTML中使用。他们有没有实现

目标?它看起来很适合HTML,但双斜线是否可以在

XHTML?


谢谢,

彼得

<!DOCTYPE HTML PUBLIC" - // W3C // DTD HTML 4.01 // EN">


< html lang =" en">

< head>

< meta http-equiv =" Content-Type"含量=" text / html的; charset = utf-8">

< title> Fork JavaScript< / title>

< / head>


< body>


< script type =" text / javascript">

//<![CDATA [

new Form.Element.Observer(''search'',0.5,function(element,value){new

Ajax.Updater(''results'',''/ cont / search'',{asynchronous:true,

evalScripts:true,parameters:value})})

//]]>

< / script>

< / div>


< / body>

< / html>

解决方案



Peter Michaux写道:


//<![CDATA [

//]]>


这个技巧是否基于HTML和XHTML的任何真实信息?我认为他们想要实现的是一种生成脚本的方法

块,可以在HTML或XHTML中使用。他们有没有实现

目标?它看起来很适合HTML,但双斜线是否可以在

XHTML中使用?



是的,这不是Rails独有的。这是SGML用于忽略

这些标记之间的任何内容。领先的斜杠是好的

因为它们在SGML语法中没有意义。这应该是

防止解析器误读任何否则将被读取为标记的字符,例如尖括号(和<)具有

javascript中的不同含义

http://www.w3.org/TR/REC-xml/#sec-cdata-sect


David


Peter Michaux写道:





我正在试验一些Ruby on Rails JavaScript

生成器并看到我以前没有的东西。也许值得吗?


在下面的页面中,脚本包含在


//<![CDATA [

//]]>


这个技巧是否基于HTML和XHTML的任何真实信息?



不是真的,这是货物崇拜/神秘咒语的事情。在HTML中,无论如何,SCRIPT元素的

内容都是CDATA,并且发布的两行

只是行尾注释。在XHTML中,SCRIPT元素

的内容是PCDATA,但是没有必要尝试注释掉CDATA

块标记。编写可以同时使用HTML DOM和XHTML DOM的非平凡的b / b $ b脚本在很大程度上是不切实际的。

不需要构造来标准化 'SCRIPT元素内容到CDATA

用于两种类型的DOM。


我认为他们想要实现的是一种方法

生成一个脚本块,可以在

HTML或XHTML中使用。



他们可能认为他们正在尝试这样做,但可能没有任何理解XHTML DOM和HTML之间的差异DOM,

所以没有对这项练习毫无价值的欣赏。


他们有没有实现这个目标?



是的,但是如果包含它们的标记被解释,那么插入到该结构中的脚本是非常可行的b / b


作为XHTML和暴露给脚本的XHTML DOM。这使得

的努力没有实际意义。


它看起来很好用于HTML但是双斜线是

ok在XHTML?



他们没问题,如果文件被解释为XHTML,那么它们包含的脚本很可能会消耗掉b
肚子通过网页

浏览器。


Richard。


David Golightly写道:


Peter Michaux写道:


> //<![CDATA [
//]] >

这个技巧是否基于HTML vs / XHTML的任何真实信息?我认为他们想要实现的是一种生成可用于HTML或
XHTML的脚本块的方法。他们有没有实现这个目标?它看起来很好用于HTML
但是在XHTML中双斜线是否正常?



是的,这不是Rails独有的。



这当然是真的。 Rails不是唯一一个在标记中包含

虚假结构的系统,没有特别好的理由。


这是SGML for忽略

这些标记之间的任何内容。



废话。 XML中的<![CDATA [...]]标记直接采用SGML形式,并且在两者中具有完全相同的含义。在HTML SCRIPT元素(已经是CDATA)的

内容的上下文中,

构造没有意义,因为这些内容未被解析为

加价,除了识别它们的结束位置。


领先的斜杠是好的

因为它们在SGML语法中没有意义。



不,它们没问题,因为HTML SCRIPT元素的内容是CDATA

,因此根本没有标记,并且XHTML脚本元素的内容

是PCDAT,因此将解析<![CDATA [和]]分隔符

之外的斜杠并使用(未更改的)结果作为脚本的一部分

源代码,CDATA块的未解析内容插入CDATA分隔符的

位置。


这应该是为了防止解析器误读任何原本会被读作标记的

字符,例如

尖括号(和<)

javascript



在没有这种误解的HTML文档中毫无价值可能是
,而在XHTML文档中,不需要结束

行注释语法。


Richard。


Hi,

I am experimenting with some of the Ruby on Rails JavaScript generators
and see something I haven''t before. Maybe it is worthwhile?

In the page below the script is enclosed in

//<![CDATA[
//]]>

Is this trick grounded in any real information about HTML vs XHTML? I
think what they are trying to achieve is a way to generate a script
block that can be used in either HTML or XHTML. Have they managed that
goal? It looks fine for HTML but will the double slashes be ok in
XHTML?

Thanks,
Peter
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">

<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Fork JavaScript</title>
</head>

<body>

<script type="text/javascript">
//<![CDATA[
new Form.Element.Observer(''search'', 0.5, function(element, value) {new
Ajax.Updater(''results'', ''/cont/search'', {asynchronous:true,
evalScripts:true, parameters:value})})
//]]>
</script>
</div>

</body>
</html>

解决方案


Peter Michaux wrote:

//<![CDATA[
//]]>

Is this trick grounded in any real information about HTML vs XHTML? I
think what they are trying to achieve is a way to generate a script
block that can be used in either HTML or XHTML. Have they managed that
goal? It looks fine for HTML but will the double slashes be ok in
XHTML?

Yes, this is not anything unique to Rails. This is SGML for "ignore
whatever comes between these marks". The leading slashes are OK
because they have no significance in SGML syntax. This is supposed to
prevent the parser from misreading any characters that would otherwise
be read as markup, such as angle brackets (and <) which have a
different meaning in javascript:

http://www.w3.org/TR/REC-xml/#sec-cdata-sect

David


Peter Michaux wrote:

Hi,

I am experimenting with some of the Ruby on Rails JavaScript
generators and see something I haven''t before. Maybe it is worthwhile?

In the page below the script is enclosed in

//<![CDATA[
//]]>

Is this trick grounded in any real information about HTML vs XHTML?

Not really, It is a cargo cult/mystical incantation thing. In HTML the
contents of SCRIPT elements are CDATA anyway and the two lines posted
are just end of line comments. In XHTML the contents of SCRIPT elements
are PCDATA, but there is no need to attempt to comment out the CDATA
block mark-up. And as it is largely impractical to write non-trivial
scripts that will function with both HTML DOMs and XHTML DOMs there is
no need for a construct to ''normalise'' SCRIPT element contents to CDATA
for use with both types of DOM.

I think what they are trying to achieve is a way to
generate a script block that can be used in either
HTML or XHTML.

They may think that they are trying to do that, but probably without any
understanding of the differences between an XHTML DOM and an HTML DOM,
and so no appreciation of the worthlessness of the exercise.

Have they managed that goal?

Yes, but the scripts being inserted into that construct are extremely
unlikely to work if the mark-up that contains them is ever interpreted
as XHTML and an XHTML DOM exposed to the script. Which renders the
effort moot.

It looks fine for HTML but will the double slashes be
ok in XHTML?

They will be fine, it is the scripts they contain that will likely go
belly-up if the documents are ever interpreted as XHTML by a web
browser.

Richard.


David Golightly wrote:

Peter Michaux wrote:

>//<![CDATA[
//]]>

Is this trick grounded in any real information about HTML vs
XHTML? I think what they are trying to achieve is a way to
generate a script block that can be used in either HTML or
XHTML. Have they managed that goal? It looks fine for HTML
but will the double slashes be ok in XHTML?


Yes, this is not anything unique to Rails.

That is certainly true. Rails is not the only system that includes
spurious constructs in mark-up for no particularly good reason.

This is SGML for "ignore
whatever comes between these marks".

Nonsense. The <![CDATA[ ... ]]mark up in XML is adopted directly form
SGML and has exactly the same meaning in both. In the context of the
contents of an HTML SCRIPT element, which is already CDATA, the
construct has no significance as such contents are not parsed for
mark-up, beyond identifying where they end.

The leading slashes are OK
because they have no significance in SGML syntax.

No, they are OK because the contents of an HTML SCRIPT element are CDATA
and so not mark-up at all, and the contents of an XHTML script element
are PCDAT and so the slashes outside the <![CDATA[ and ]]delimiters
will be parsed and the (unchanged) results used as part of the script
source code, with the unparsed contents of the CDATA block inserted in
place of the CDATA delimiters.

This is supposed to prevent the parser from misreading any
characters that would otherwise be read as markup, such as
angle brackets (and <) which have a different meaning in
javascript:

And is worthless in an HTML document where no such misinterpretation is
possible, while in an XHTML document there is no need for the end of
line comment syntax.

Richard.


这篇关于由Rails生成的HTML和CDATA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆