5

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.

eros
  • 4,946
  • 18
  • 53
  • 78

2 Answers2

5

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.

cordsen
  • 1,691
  • 12
  • 10
0

*[@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.

Richard Schneider
  • 34,944
  • 9
  • 57
  • 73
  • I can get the element of the current context which has the given attribute but not the grandchildren elements. e.g. current context: i can get: only – eros Jun 09 '11 at 03:40
  • it refers that * is children of the current context only not including the grandchildren. – eros Jun 09 '11 at 03:43