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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…