XPATH Syntax, Operators

Estudies4you
XPATH Syntax, Operators
XPATH Syntax, Operators
  • XPath uses path expressions to select nodes or node-sets in an XML document
  • The node is selected by following a path or steps
  • The most useful path expressions are listed below:

Expression
Description
nodename
Selects all nodes with the name "nodename"
/
Selects from the root node
//
Selects nodes in the document from the current node that match the selection no matter where they are
.
Selects the current node
..
Selects the parent of the current node
@
Selects attributes
/bookstore/book[1]
Selects the first book element that is the child of the bookstore element.Note: 1E5 and later has implemented that [0] should be the first node, but according to the W3C standard it should have been [1]!!
/bookstore/book[last()]
Selects the last book element that is the child of the bookstore element
/bookstore/book[last()-1]
Selects the last but one book element that is the child of the bookstore element
/bookstore/book[position()<3]
Selects the first two book elements that are children of the bookstore element
//title[@lang]
Selects all the title elements that have an attribute named lang
//titler@lang=’eng’]
Selects all the title elements that have an attribute named lang with a value of 'eng'
/bookstore/book[price>35.00]
Selects all the book elements of the bookstore element that have a price element with a value greater than 35.00

/bookstore/book[price>35.00]/title
Selects all the title elements of the book elements of the bookstore element that have a price element with a value greater than 35.00

To Top