views:

299

answers:

3

Hi!

Is there a generic way of determining all attributes (and their values) from an XML node using XQuery/XPath?

thx, Alex

+1  A: 

Get all attributes for the current node using XPath:

@*

Is that what you're after?

The names and values of the attributes can be extracted per attribute:

name(@*[1])
string(@*[1])

Depends on what you want to do with them.

Welbog
yeah that's for the values, and i also need the attributenames
alex
You'll need to iterate through the attribute nodes returned by this. There's no way that I'm aware of to write one xpath query that will return a list of key value pairs for the attributes of an element node. (This answer returns a nodeset of attribute nodes, the node name is available with another xpath query)
MattH
+1  A: 

return for $att in $doc//@* return (fn:concat(name($att),"=","'",$att,"'"))

kadalamittai
A: 

$doc//@*/(concat(name(.),"=",.))

Chris Wallace