Dimitre wrote:
You haven't defined what should "empty" mean exactly.
Therefore, *any* XPath expression attempting to express
this undefined concept of "empty" is potentially wrong.
Fantastic Dimitre! You are spot on. I did not define what I mean by “empty element”.
I would like to do so now.
First, examples of what I consider to be empty elements and examples of elements that I consider not empty.
In the following instance document, the B element is empty:
<Row>
<A>foo</A>
<B/>
<C>bar</C>
</Row>
In the following instance document the B element is empty:
<Row>
<A>foo</A>
<B></B>
<C>bar</C>
</Row>
In the following instance document the B element is empty:
<!DOCTYPE Row [
<!ENTITY null ''>
]>
<Row>
<A>foo</A>
<B>&null;</B>
<C>bar</C>
</Row>
In the following instance document the B element is
not empty:
<Row>
<A>foo</A>
<B> </B>
<C>bar</C>
</Row>
In the following instance document the B element is
not empty:
<Row>
<A>foo</A>
<B><!-- Hello, world --></B>
<C>bar</C>
</Row>
In the following instance document the B element is
not empty:
<Row>
<A>foo</A>
<B><?my-pi x="blah"?></B>
<C>bar</C>
</Row>
In the following instance document the B element is
not empty:
<Row>
<A>foo</A>
<B><bad/></B>
<C>bar</C>
</Row>
In the following instance document the B element is
not empty:
<Row>
<A>foo</A>
<B>99</B>
<C>bar</C>
</Row>
In the following instance document the B element is
not empty:
<Row>
<A>foo</A>
<B x="10"/>
<C>bar</C>
</Row>
Those examples illustrate what I mean by an “empty element.” Now for a definition.
[Definition] An element is empty if and only if the element consists of a text node containing a string of length zero and nothing else (no attribute, comment, processing instruction, child element,
or non-string value).
Is that definition 100% precise? Does it cover every possible case? Can it be stated more succinctly and precisely?
/Roger