bosari
bosari

Reputation: 2010

How to get all attribute names, not values of a particular node from the XML?

Suppose I have an XML-

<SearchPage ID="123" version="1.3" xmlns="http://some/path">
   .....some child elements
</SearchPage>  

How to get all the attribute names from it?

Upvotes: 1

Views: 415

Answers (1)

Jens Erat
Jens Erat

Reputation: 38732

Use the name() function, or local-name() if you want to omit attribute namespaces.

let $node := <SearchPage ID="123" version="1.3" xmlns="http://some/path">
               .....some child elements
             </SearchPage>
for $attribute in $node/attribute()
return $attribute/name()

with result:

ID
version

Upvotes: 5

Related Questions