开发者

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

开发者 https://www.devze.com 2023-03-11 05:16 出处:网络
xml: <root0> <elem1> <elem21 xlink:href=\"21\"/> <elem22> <elem31 xlink:href=\"31\"/>

xml:

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

th开发者_如何学Pythone 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.


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.


*[@xlink:href] should work. It is most likely that you have not defined the xlink namespace.

If you post the code, then I can be more precise in my answer.

0

精彩评论

暂无评论...
验证码 换一张
取 消