XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
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]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS