Reputation: 43
Is there a generic way of determining all attributes (and their values) from an XML node using XQuery/XPath?
<parent>
<something attr1="123" attrA="abc" ..... attrAnythingelse="blablabla"/>
</parent>
Upvotes: 4
Views: 9526
Reputation: 11
DECLARE @xml XML
SET @xml = '<a attr1="5 < 6" attr2="50 > 20"/>'
SELECT
t.c.value('local-name(.)', 'varchar(128)'),
t.c.value('.', 'varchar(128)')
FROM
@xml.nodes('/a/@*') as t(c)
you get
attr_name | attr_value |
---|---|
attr1 | 5 < 6 |
attr2 | 50 > 20 |
Upvotes: 0
Reputation: 102
Get all attributes with their values using XQuery:
for $attr in //@*
return concat(name($attr), " = "", $attr, "" ")
Upvotes: 0
Reputation: 2166
Try this command:
return for $att in $doc//@*
return (fn:concat(name($att),"=","'",$att,"'"))
Upvotes: 1
Reputation: 60378
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.
Upvotes: 4