[Home] [By Thread] [By Date] [Recent Entries]

  • From: "Costello, Roger L." <costello@m...>
  • To: "xml-dev@l..." <xml-dev@l...>
  • Date: Sat, 24 Sep 2016 12:27:29 +0000

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



[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member