3
votes

How would an Xpath expression look like that retrieves all attribute names (not attribute values!) for a given node resp. xml tag?

Assume the following XML document:

<bookstore>
  <book>
    <title lang="eng">Harry Potter</title>
    <price>29.99</price>
  </book>
  <book>
    <title lang="fr" type="easyreading">Monsieur Claude</title>
    <price>39.95</price>
  </book>
</bookstore>

The Xpath //title/@* would select "eng, fr, easyreading", but which Xpath would select "lang, lang, type"?

1
What version of XPath are you ussing? XPath 1.0 has no sequence data type but it has a node-set data type.Alejandro

1 Answers

4
votes

Give this a try:

//@*/name()

returns

String='lang'
String='lang'
String='type'

See here regarding the name() function.