Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XPath: How to: select all children and grandchildren (regardless of depth) with the given attribute name of the current context?

Tags:

xml

xpath

depth

xml:

<root0>
    <elem1>
        <elem21 xlink:href="21"/>
        <elem22>
            <elem31 xlink:href="31"/>
            <elem32>
                <elem41 xlink:href="41"/>
            </elem32>
        </elem22>
    </elem1>
</root0>

the depth is unknown. How can I select all elements with xlink:href attribute?

I tried the following:

*[@xlink:href]
self::*[@xlink:href]

Any guidance is appreciated.

like image 625
eros Avatar asked Oct 11 '22 19:10

eros


1 Answers

For just children of grandchildren use

descendant-or-self::*[@xlink:href]

For all nodes just add // in front of your xpath

//*[@xlink:href]

Also, your xml sample is not valid but I'm guessing it is just a sample.

like image 129
cordsen Avatar answered Oct 14 '22 02:10

cordsen