关于空元素的XHTML用户代理行为 [英] XHTML user agent behavior regarding empty elements

查看:44
本文介绍了关于空元素的XHTML用户代理行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自XML规范:


[定义:没有内容的元素被认为是空的。]空元素的

表示要么是一个开始标记立即

后跟一个结束标记或一个空元素标记。


(这意味着< foo>< / foo>等于< foo />)


来自XHTML规范:


C.3。元素最小化和空元素内容

给定内容模型不是EMPTY的元素的空实例

(例如,空标题或段落)不使用最小化表格

(例如使用< p>< / p>而不是< p />)。


从XML的角度来看< DIV />和< div>< / div>是平等的。但是,XHTML,

应该是有效的XML,建议(?)使用< div>< / div>只要。应该

XHTML浏览器是否接受空元素标签?


一点点测试表明情况并非如此。 IE 5.5和Netscape

7.0都无法正确呈现XHTML代码。他们认为

空元素标签< div />等于< div> ;.


这是令人讨厌的,因为当您使用XSLT从XML生成XHTML

转换时,XSLT转换器使用空呈现空元素 - 元素

标记符号。您必须使用外部后处理器将< div />

元素更改为< div>< / div>对。


<?xml version =" 1.0"编码= QUOT; UTF-8英寸?>

< html>

< body>


< div style =" margin-left: 10%; background:blue">

工作样本。

< div style =" margin-left:10%;背景:红色>

Lalihoo!

< div id =" blaah">< / div>

我是红色?

< / div>

我是蓝色吗?

< / div>


< br />


< div style =" margin-left:10%;背景:蓝色>

Hiihoo!


< div style =" margin-left:10%;背景:红色>

Lalihoo!

< div id =" blaah" />

我是红色吗?

< / div>

我是蓝色的吗?不,我很红,因为我很困惑。

< / div>

< / body>

< / html>

From XML specification:

[Definition: An element with no content is said to be empty.] The
representation of an empty element is either a start-tag immediately
followed by an end-tag, or an empty-element tag.

(This means that <foo></foo> is equal to <foo/>)

From XHTML specification:

C.3. Element Minimization and Empty Element Content
Given an empty instance of an element whose content model is not EMPTY
(for example, an empty title or paragraph) do not use the minimized form
(e.g. use <p> </p> and not <p />).

From XML point of view <div/> and <div></div> are equal. However, XHTML,
which should be valid XML, recommends(?) to use <div></div> only. Should
XHTML browsers accept empty-element tags?

A little testing shows that this is not the case. Both IE 5.5 and Netscape
7.0 fail to render following XHTML code correctly. They consider
empty-element tag <div/> equal to <div>.

This is nuisance, since when you are producing XHTML from XML with XSLT
transform, XSLT transformers present empty elements using empty-element
tag notation. You must use external postprocessor to change <div/>
elements to <div></div> pairs.

<?xml version="1.0" encoding="utf-8" ?>
<html>
<body>

<div style="margin-left: 10%; background: blue">
A working sample.
<div style="margin-left: 10%; background: red">
Lalihoo!
<div id="blaah"></div>
Am I red?
</div>
Am I blue?
</div>

<br/>

<div style="margin-left: 10%; background: blue">
Hiihoo!

<div style="margin-left: 10%; background: red">
Lalihoo!
<div id="blaah"/>
Am I red?
</div>
Am I blue? No, I am red because I am confused.
</div>
</body>
</html>

推荐答案

" Mikko Ohtamaa" < mo*@sneakmail.zzn.com> schrieb im Newsbeitrag

news:26 ************************** @ posting.google.c om ...
"Mikko Ohtamaa" <mo*@sneakmail.zzn.com> schrieb im Newsbeitrag
news:26**************************@posting.google.c om...
来自XML规范:

[定义:没有内容的元素被认为是空的。]空元素的
表示是一个开始 - 标签后面紧跟
后跟一个结束标签或空元素标签。

(这意味着< foo>< / foo>等于< foo /> )

来自XHTML规范:

C.3。元素最小化和空元素内容
给定内容模型不是EMPTY的元素的空实例(例如,空标题或段落)不使用最小化的形式
(例如使用< p>< / p>而不是< p />)。

从XML的角度来看< div />和< div>< / div>是平等的。但是,XHTML,
应该是有效的XML,建议(?)使用< div>< / div>只要。应该XHTML浏览器接受空元素标签吗?


a)C.3中的引用来自(非规范性)章节HTML兼容性

指南。

b)他们必须。

一点点测试表明情况并非如此。 IE 5.5和Netscape
7.0都无法正确呈现XHTML代码。他们认为
空元素标签< div />等于< div>。


IE已知不支持XHTML。对于NS 7,这可能是需要修复
的错误。确保您以浏览器

* *知道*这不是HTML的方式提供XHTML。

...
From XML specification:

[Definition: An element with no content is said to be empty.] The
representation of an empty element is either a start-tag immediately
followed by an end-tag, or an empty-element tag.

(This means that <foo></foo> is equal to <foo/>)

From XHTML specification:

C.3. Element Minimization and Empty Element Content
Given an empty instance of an element whose content model is not EMPTY
(for example, an empty title or paragraph) do not use the minimized form
(e.g. use <p> </p> and not <p />).

From XML point of view <div/> and <div></div> are equal. However, XHTML,
which should be valid XML, recommends(?) to use <div></div> only. Should
XHTML browsers accept empty-element tags?
a) The quote in C.3 is from the (non-normative) chapter "HTML compatibility
guidelines".

b) They must.
A little testing shows that this is not the case. Both IE 5.5 and Netscape
7.0 fail to render following XHTML code correctly. They consider
empty-element tag <div/> equal to <div>.
IE is known not to support XHTML. For NS 7, this may be a bug that needs to
be fixed. Make sure that you are serving the XHTML in a way that the browser
is *aware* that this is not HTML, though.
...




Julian



Julian


Mikko Ohtamaa写道:
Mikko Ohtamaa wrote:
来自XML规范:
[定义:没有内容的元素被认为是空的。]空元素的
表示是立即开始标记
后跟结束标记,或者是空元素标记。

(这意味着< foo>< / foo>等于< foo />)

来自XHTML规范:

给定内容模型不是EMPTY的元素的空实例(例如,空标题或段落)不使用最小化的形式
(例如使用< p>< / p>而不是< p />)。

从XML的角度来看< div />和< div>< / div>是平等的。


来自XML 1.0第二版:

空元素标签可用于任何没有内容的元素,

是否是否使用关键字EMPTY声明它。对于

互操作性,应该使用empty-element标签,并且对于声明为EMPTY的元素,只应使用


但是,XHTML,
哪些应该是有效的XML,建议(?)使用< div>< / div>只要。应该XHTML浏览器接受空元素标签吗?


是的,他们应该。

一点点测试表明情况并非如此。 IE 5.5和Netscape
7.0都无法正确呈现XHTML代码。


IE 5.5不是XHTML浏览器,也许它可以被称为XML浏览器。

在各种浏览器中,XML规则仅在内容已知时应用

是XML(通过适当的Content-Type HTTP标头)。

他们认为
空元素标签< div />等于< div>。
From XML specification:

[Definition: An element with no content is said to be empty.] The
representation of an empty element is either a start-tag immediately
followed by an end-tag, or an empty-element tag.

(This means that <foo></foo> is equal to <foo/>)

From XHTML specification:

C.3. Element Minimization and Empty Element Content
Given an empty instance of an element whose content model is not EMPTY
(for example, an empty title or paragraph) do not use the minimized form
(e.g. use <p> </p> and not <p />).

From XML point of view <div/> and <div></div> are equal.
From XML 1.0 Second Edition:
Empty-element tags may be used for any element which has no content,
whether or not it is declared using the keyword EMPTY. For
interoperability, the empty-element tag should be used, and should only
be used, for elements which are declared EMPTY.
However, XHTML,
which should be valid XML, recommends(?) to use <div></div> only. Should
XHTML browsers accept empty-element tags?
Yes, they should.
A little testing shows that this is not the case. Both IE 5.5 and Netscape
7.0 fail to render following XHTML code correctly.
IE 5.5 is no XHTML browser, maybe it can be called an XML browser.
In various browsers XML rules are only applied when the content is known
to be XML (via an appropriate Content-Type HTTP header).
They consider
empty-element tag <div/> equal to <div>.




在标签汤模式中。


没有f''up2设置,因为它可能对两个小组都很有意思。

-

Johannes Koch

在te domine speravi;非永久性的东西。

(Te Deum,4美分。)



In tag soup mode.

No f''up2 set, because it may be interesting for both groups.
--
Johannes Koch
In te domine speravi; non confundar in aeternum.
(Te Deum, 4th cent.)


mo*@sneakmail.zzn.com (Mikko Ohtamaa)写道:
mo*@sneakmail.zzn.com (Mikko Ohtamaa) wrote:
来自XHTML规范:

C 0.3。元素最小化和空元素内容
给定一个元素的空实例,其内容模型不是空的(例如,空标题或段落)不使用
最小化形式(例如使用< p>< / p>而不是< p />)。


我认为需要提到的是,HTML 4.01规范

明确地对空段落皱眉,并说作者不应该使用

他们和浏览器应该忽略它们。目前尚不清楚是否< p> < / p为H.

是否空;一个空格字符,因为内容与缺少

内容不同(以及常见构造< p>& nbsp;< / p>各种程序

吐出是另一回事。)

一点点测试表明情况并非如此。 IE 5.5和
Netscape 7.0都无法正确呈现XHTML代码。他们考虑空元素标签< div />等于< div>。


难怪。有传闻说甚至还有一些小型浏览器可以处理构造< div /> _correctly_由HTML规则有效,最高为

,包括HTML 4.01,即等同于< div>> (其中第二个

大于符号是数据字符)。

这是令人讨厌的,因为当您使用XSLT转换从XML生成XHTML时,XSLT变换器使用
空元素标记表示空元素。您必须使用外部后处理器来更改< div />元素到< div>< / div>对。
From XHTML specification:

C.3. Element Minimization and Empty Element Content
Given an empty instance of an element whose content model is not
EMPTY (for example, an empty title or paragraph) do not use the
minimized form (e.g. use <p> </p> and not <p />).
I think it needs to be mentioned that the HTML 4.01 specification
explicitly frowns upon empty paragraphs and says authors should not use
them and browsers shoulds ignore them. It''s not clear whether <p> </p> is
empty or not; a space character as the content is not the same as lack of
content (and the common construct <p>&nbsp;</p> that various programs
spit out is a yet another thing).
A little testing shows that this is not the case. Both IE 5.5 and
Netscape 7.0 fail to render following XHTML code correctly. They
consider empty-element tag <div/> equal to <div>.
No wonder. And rumors say that there are even some small browsers that
process the construct <div/> _correctly_ by HTML rules as valid up to and
including HTML 4.01, namely as equivalent to <div>> (where the second
greater than sign is a data character).
This is nuisance, since when you are producing XHTML from XML with
XSLT transform, XSLT transformers present empty elements using
empty-element tag notation. You must use external postprocessor to
change <div/> elements to <div></div> pairs.




为什么你首先生成具有空内容的元素?

< div>的含义是什么?没有内容的元素,请给出

< div>元素没有语义,除了在抽象意义上它是什么?b $ b构成一个块元素?


空元素非常混乱,请参阅
< a rel =nofollowhref =http://www.cs.tut.fi/~jkorpela/html/empty.html\"target =_ blank> http://www.cs.tut.fi/~jkorpela /html/empty.html


-

Yucca, http://www.cs.tut.fi/~jkorpela/

有关网页制作的网页: http://www.cs.tut.fi/~jkorpela/www。 HTML



Why do you generate elements with empty content in the first place?
What is the meaning of a <div> element with no content, give that the
<div> element has no semantics except in the abstract sense that it
constitutes a block-element element?

Empty elements are extremely confusing, see
http://www.cs.tut.fi/~jkorpela/html/empty.html

--
Yucca, http://www.cs.tut.fi/~jkorpela/
Pages about Web authoring: http://www.cs.tut.fi/~jkorpela/www.html


这篇关于关于空元素的XHTML用户代理行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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