The best XPath Examples Tutorial In 2024, In this tutorial you can learn XML instance documents,Load an XML document,Select node,Select all title,Examples,Select the first title of a book,Examples,Examples,Select all prices,Examples,Select the price is higher than the price node 35,Examples,Select the node price is higher than 35 title,Examples,
In this section, let us learn by example to some basic XPath syntax.
We will use this XML document in the following example:
"Books.xml":
View "books.xml" file in your browser .
All modern browsers support the use of XMLHttpRequest to load XML documents.
For most modern browsers code:
For the old Microsoft browser (IE 5 and 6) of the Code:
Unfortunately, Internet Explorer and other different way of handling XPath.
In our example, it contained for most major browsers code.
Internet Explorer uses selectNodes () method from the XML document to select nodes:
Firefox, Chrome, Opera and Safari use the evaluate () method to select nodes from the XML document:
The following examples select all title nodes:
The following examples select bookstore element below the first book node title:
There is a problem. The above examples of different results in IE and other browsers.
IE5 and later the [0] regarded as the first node, and according to the W3C standards should be [1].
In order to solve the IE5 + [0] and [1] of the problem, you can set the language selection for the XPath (SelectionLanguage).
The following examples select bookstore element below the first book node title:
The following examples select all the text node price:
The following examples select all price higher than the price of 35 nodes:
The following examples select all the title nodes prices higher than 35: