You can do it by getting the title
child and check if there is the following price
sibling:
//book[title/following-sibling::price]
Demo (using xmllint
):
$ xmllint input.xml --xpath '//book[title/following-sibling::price]'
<book>
<title lang="eng">Harry Potter</title>
<price>29.99</price>
</book>
Another approach would be to check the name()
s of the first and second children of book
node:
//book[name(*[1]) = "title" and name(*[2]) = "price"]