e.g:
DECLARE @xmlSource XML SET @xmlSource = '<t topA="1"> <a x="2" z="3"> <b message="Hello"/> </a> <c y="5"/> </t>' SELECT @xmlSource.query('data(//@*)'); SELECT @xmlSource.query('for $nodes in //*, $attr in $nodes/@* return (local-name($attr),string($attr), ''
'')');
结果:
1 2 3 Hello 5 topA 1 x 2 z 3 message Hello y 5
local-name($attr)获取属性的名称
string($attr)获取属性的值
'
'可认为是格式化,用于换行,如果没有加则结果如下:
topA 1 x 2 z 3 message Hello y 5