开发者

XQuery to get a list of all attributes an element has

开发者 https://www.devze.com 2022-12-25 16:38 出处:网络
Is there a generic way of determining all attributes (and 开发者_C百科their values) from an XML node using XQuery/XPath?

Is there a generic way of determining all attributes (and 开发者_C百科their values) from an XML node using XQuery/XPath?

<parent>
   <something attr1="123" attrA="abc" ..... attrAnythingelse="blablabla"/>
</parent>


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.


Try this command:

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


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


Get all attributes with their values using XQuery:

for $attr in //@*
return concat(name($attr), " = &quot;", $attr, "&quot;&#10;")
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号