Hi Folks,
A few days ago David Carlisle posted
a message with an excellent analysis of several XPath expressions. His message got me to thinking: It’s really easy to write XPath expressions that yield
false positives. Stated differently,
it’s really hard to write correct XPath expressions.
[Definition]
False positive: a test result which incorrectly indicates that a particular condition or attribute is present.
Example of a Condition:
The <B> element is empty.
Will the following XPath correctly indicate when the condition is present?
normalize-space(B) eq ''
Evaluating the XPath expression on the following XML correctly indicates that the condition is present.
<Row>
<A>foo</A>
<B/>
<C>bar</C>
</Row>
Evaluating the XPath expression on the following XML correctly indicates that the condition is not present.
<Row>
<A>foo</A>
<B>99</B>
<C>bar</C>
</Row>
Evaluating the XPath expression on the following XML
incorrectly indicates that the condition is present.
<Row>
<A>foo</A>
<B><bad/></B>
<C>bar</C>
</Row>
Evaluating the XPath expression produces a false positive.
Evaluating the XPath expression on the following XML
incorrectly indicates that the condition is present.
<Row>
<A>foo</A>
<B><!-- Hello, world --></B>
<C>bar</C>
</Row>
Evaluating the XPath expression produces a false positive.
/Roger