tags:

views:

133

answers:

2

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?

A: 
<element />

and

<element></element>

are both empty elements. Any productions from standards must be interpreted to have this result.

John Saunders
I am glad to believe it, but how do you explain the text I quoted from the spec. In other words, why do the rules take precedence so that this is the outcome?
Roland Bouman
@Roland: I don't explain it. Perhaps you misread it, or misunderstood.
John Saunders
+2  A: 

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

Thilo
Well, I guess the example does make a difference, but I disagree that the only way to read "An element with no content" is as you describe. I mean, in the spec, this occurrence of "content" hyperlinks to production rule 43. I am starting to believe production rule 43 is wonky, and should have been defined to always match at least one character or element.
Roland Bouman
Ok - considering this answered because the example shows it. Thanks!
Roland Bouman