. NET XML node read detailed
Note: If the path starts with a forward slash (/), the path always represents an absolute path to an element!
Bookstore/book selects all the book elements that belong to the bookstore child element.
Book selects all book child elements, regardless of their position in the document.
Bookstore//book selects all the book elements that belong to descendants of the bookstore element, regardless of where they are located under bookstore.
//@lang Select all properties named Lang.
predicate (predicates)
predicate pragmatics to find a particular node or a node that contains a specified value.
The predicate is embedded in square brackets.
Instance
In the table below, we list some path expressions with predicates, and the results of expressions:
Path expression Results
/BOOKSTORE/BOOK[1] Selects the first book element that belongs to the bookstore child element.
/bookstore/book[last ()] selects the last book element that belongs to the bookstore child element.
/bookstore/book[last ()-1] selects the penultimate book element that belongs to the bookstore child element.
/bookstore/book[position () <3] selects the book element with the first two child elements that belong to the bookstore element.
title[@lang] Select all title elements that have properties named Lang.
title[@lang = ' eng '] selects all the title elements, and these elements have the lang attribute with the value eng.
/bookstore/book[price>35.00] selects the book element of all bookstore elements, and the value of the price element must be greater than 35.00.
/bookstore/book[price>35.00]/title selects the title element of the book element in all bookstore elements, and the value of the price element must be greater than 35.00.
Select Unknown node
XPath wildcard characters can be used to select an unknown XML element.
Wildcard description
* Match any element node
@* matches any attribute node
Node () matches nodes of any type
Instance
In the following table, we list some path expressions and the results of those expressions:
Path expression Results
/bookstore/* Select all child nodes of the bookstore element
* Select all elements in the document
TITLE[@*] Selects all the title elements with attributes.
Select several paths
By using the "|" in a path expression operator, you can select several paths.
Instance
In the following table, we list some path expressions and the results of those expressions:
Path expression Results
Book/title | Book/price selects the title and price elements of all book elements.
Title | Price selects the title and price elements in all documents.
/bookstore/book/title | Price selects all the title elements of the book element that belong to the bookstore element, and all the price elements in the document.