Eddy
Eddy

Reputation: 31

Getting attribute name (not attribute value) with Xpath

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"?

Upvotes: 3

Views: 784

Answers (1)

OldProgrammer
OldProgrammer

Reputation: 12159

Give this a try:

//@*/name()

returns

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

See here regarding the name() function.

Upvotes: 5

Related Questions