Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
722 views
in Technique[技术] by (71.8m points)

xml - What is an empty element?

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.

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

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?)*

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.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...