I am new to xpath can anyone let me now in detail what is the difference between /bookstore/*
and /bookstore
in xpath?
let say this is example input
<bookstore>
<book>
<title lang="en">Harry Potter</title>
<price>29.99</price>
</book>
<book>
<title lang="en">Learning XML</title>
<price>39.95</price>
</book>
</bookstore>
<bookstore>
<book>
<title lang="en">Harry Potter1</title>
<price>29.999</price>
</book>
<book>
<title lang="en">Learning XML1</title>
<price>39.955</price>
</book>
</bookstore>
what will be output in both cases? Thanks in advance.
The expression /bookstore/*
will select children, /bookstore
will select the node itself.
For instance, /bookstore/*
will select all child elements under /bookstore
, so you may end up with a collection of elements. Note that in case this is a more complex expression like /bookstore/book/*
and there are multiple /bookstore/book
elements, all children of all matching nodes are selected.
The expression /bookstore
will select only the element(s) /bookstore
. Similarily to the above, such select may result in a collection of elements if it's down the path like /bookstore/book
.