Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Example

Description

/bookstore/book[@price>800]Select price nodes with price>800
/bookstore/book[@price>800 and @price<1000]Select price nodes between 800-1000 /bookstore/book[@price>800]/titleselects all the title nodes with a price higher than 800with price<1000

NOTE: We can add limit to above examples as a query parameter

...

           

Example 

Description

/bookstore/book/books[contains(@language,'En')] 

It is used when the value of any attribute changes dynamically, The contain feature has an ability to find the element with partial text as shown in below XPath example:


XPath expression partial value ‘En’ is used in place English



...

3.Using OR & AND functions

Example

Description

/bookstore/book/books[@title='The Golden compass' or @lang='english']
  • In OR expression, two conditions are used, whether 1st condition OR 2nd condition should be true. It is also applicable if any one condition is true or maybe both. Means any one condition should be true to find the element.
  • In this XPath expression, it identifies the elements whose single or both conditions are true.
 /bookstore/book/books[@title='The Golden compass' and @lang='english']
  • In AND expression, two conditions are used, both conditions should be true to find the element. It fails to find element if any one condition is false.

...