I am trying to modify a chunk of xml and insert extra information without altering the original info.
Given an xml document such as the following:
<xml>
<node att1="a" att2="b"/>
<node att1="c" att99="d"/>
</xml>
I want to achieve the following output:
<xml>
<node extra="hello" att1="a" att2="b"><More/></node>
<node extra="hello" att1="c" att99="d"><More/></node>
</xml>
The part I'm stuck on is copying the existing attributes to the new xml tree.
SELECT 'hello' AS [@extra],
T.C.query('@*') AS [*] --this line doesn't work
FROM @xml.nodes('/xml/node') T(C)
FOR XML PATH ('xml')
I kind of hoped that the T.C.query('@*') AS [*]
part would just copy the attributes but no joy.
How can I copy all the attributes without knowing their names?