Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XPath for elements at multiple levels?

I have a following XML

<?xml version="1.0" encoding="UTF-8"?>
<stationary>
    <textbook>
        <name>test</name>
    </textbook>
    <notebook>
        <books>
            <name>test</name>
        </books>
    </notebook>
</stationary>

I am trying to get all name elements irrespective of their position in stationary

I have tried using the following syntax but it didn't work:

stationary/*/name/text()
like image 750
S Jagdeesh Avatar asked Dec 24 '22 09:12

S Jagdeesh


2 Answers

Try this :

'stationary//name/text()'
like image 112
Gilles Quenot Avatar answered Jan 01 '23 11:01

Gilles Quenot


Just use the following expression with a relative path:

//name

This seems to capture the two <name> tags you have in your XML sample:

Element='<name>test</name>'
Element='<name>test</name>'
like image 24
Tim Biegeleisen Avatar answered Jan 01 '23 10:01

Tim Biegeleisen