,
Expression | \n", "Description | \n", "
---|---|
nodename | \n", "Selects all nodes with the name \"nodename\" | \n", "
/ | \n", "Selects from the root node | \n", "
// | \n", "Selects nodes in the document from the current node that match the selection no matter where they are | \n", "
. | \n", "Selects the current node | \n", "
.. | \n", "Selects the parent of the current node | \n", "
@ | \n", "Selects attributes | \n", "
Path Expression | \n", "Result | \n", "
---|---|
bookstore | \n", "Selects all nodes with the name \"bookstore\" | \n", "
/bookstore | \n", "Selects the root element bookstore Note: If the path starts with a slash ( / ) it always represents an absolute \n", "path to an element! | \n",
"
bookstore/book | \n", "Selects all book elements that are children of bookstore | \n", "
//book | \n", "Selects all book elements no matter where they are in the document | \n", "
bookstore//book | \n", "Selects all book elements that are descendant of the bookstore element, no matter where they are under the bookstore element | \n", "
//@lang | \n", "Selects all attributes that are named lang | \n", "
Path Expression | \n", "Result | \n", "
---|---|
/bookstore/book[1] | \n", "Selects the first book element that is the child of the bookstore element.\n",
" Note: In IE 5,6,7,8,9 first node is[0], but according to W3C, it is [1]. To solve this problem in IE, set the SelectionLanguage to XPath: \n", " In JavaScript: xml.setProperty(\"SelectionLanguage\",\"XPath\"); | \n",
"
/bookstore/book[last()] | \n", "Selects the last book element that is the child of the bookstore element | \n", "
/bookstore/book[last()-1] | \n", "Selects the last but one book element that is the child of the bookstore element | \n", "
/bookstore/book[position()<3] | \n", "Selects the first two book elements that are children of the bookstore element | \n", "
//title[@lang] | \n", "Selects all the title elements that have an attribute named lang | \n", "
//title[@lang='en'] | \n", "Selects all the title elements that have a \"lang\" attribute with a value of \"en\" | \n", "
/bookstore/book[price>35.00] | \n", "Selects all the book elements of the bookstore element that have a price element with a value greater than 35.00 | \n", "
/bookstore/book[price>35.00]/title | \n", "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 | \n", "
Wildcard | \n", "Description | \n", "
---|---|
* | \n", "Matches any element node | \n", "
@* | \n", "Matches any attribute node | \n", "
node() | \n", "Matches any node of any kind | \n", "
Path Expression | \n", "Result | \n", "
---|---|
/bookstore/* | \n", "Selects all the child element nodes of the bookstore element | \n", "
//* | \n", "Selects all elements in the document | \n", "
//title[@*] | \n", "Selects all title elements which have at least one attribute of any kind | \n", "
Path Expression | \n", "Result | \n", "
---|---|
//book/title | //book/price | \n", "Selects all the title AND price elements of all book elements | \n", "
//title | //price | \n", "Selects all the title AND price elements in the document | \n", "
/bookstore/book/title | //price | \n", "Selects all the title elements of the book element of the bookstore element AND all the price elements in the document | \n", "