什么是空元素? [英] What is an empty element?

查看:182
本文介绍了什么是空元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据XML规范,这是一个空白元素的定义:

According to the XML spec, this is the definition of an empty element:


没有内容的元素被认为是空的。]空元素的表示是一个开始标签,紧跟着一个结束标签或一个空元素标签。

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.

(见: http://www.w3.org/TR/REC -xml /#NT-content

现在,我解释空元素标签没有问题:< i-am -empty /> ,不会有误会。但是在我看来,这个标准在另一种情况下是矛盾的:一方面,它表示没有内容的标签是空的,另一方面它表示这个可以由开始标签表示,紧跟着结束标签。但是,如果我们查看内容的定义:

Now, I have no problem understanding empty-element tags: <i-am-empty/> and no misunderstanding is possible. But it seems to me the standard contradicts itself in the other case: on the one hand it says that any tag with no content is empty, on the other hand it says that this can be represented by a start-tag followed immediately by an end-tag. But if we look at the definition of content:

[43] content ::= CharData? ((element | Reference | CDSect | PI | Comment) CharData?)*

内容由两个可选部分组成, CharData?和组()* 。但是由于这两个部分都是可选的,所以这意味着没有任何东西(如没有字符)匹配这个生产。如果我尝试将这个内容的定义与< am-i-empty-or-not>< / am-i-empty-or-not> 我会得到一个积极的比赛。所以,一方面这是一个空的标签,因为它是一个开始标签,紧随其后的是一个结束标签,另一方面它不是空的,因为标签之间可以肯定地匹配生产规则的定义[ 43]的内容,在这种情况下它包含内容,这意味着它不能为空。

It seems to me that content consists of two optional parts, CharData? and a group ()*. But since both these parts are optional, it would mean that nothing (as in, absence of characters) matches this production. SO if I would try to match this definition of content to whatever is inside <am-i-empty-or-not></am-i-empty-or-not> I would get a positive match. So, on the one hand this is an empty tag because it is "a start-tag immediately followed by an end-tag", on the other hand it is not empty because between the tags I can positively match the definition of production rule [43] for content, in which case it contains content, which means it can't be empty.

任何人可以解释什么规则优先?有没有人知道对此有不同意见的任何DOM或解析器实现?

Can anybody explain what rules take precedence? Does anybody know about any DOM or parser implementations that have differrent opinions on this?

推荐答案


但是这两个部分都是可选的,这意味着没有任何内容(如没有字符)与此生产匹配。

But since both these parts are optional, it would mean that nothing (as in, absence of characters) matches this production.

这可能是真的但在这个问题上的规范中的措词是很清楚的。甚至还有下一段的空白元素的例子。

That may be true, but the wording in the spec on this issue is quite clear. There are even examples for empty elements in the next paragraph.

<IMG align="left"
 src="http://www.w3.org/Icons/WWW/w3c_home" />
<br></br>
<br/>

所以唯一的方式(在这个上下文中,附带的措辞和例子)读取

So the only way (in this context, with the surrounding wording and examples) to read


没有内容的元素

An element with no content

将是包括(与生产匹配的内容)完全为空(即零长度,甚至不是空格)。

would be to include "content that (while matching the production) is completely empty" (i.e. zero-length, not even white-space).

这篇关于什么是空元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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