[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Beware of XPath expressions that produce false positives

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

Beware of XPath expressions that produce false positives

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]


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.