For the following .nodes() approach, I need an equivalent OPENXML approach. The Attributes will be different and can not be hard-coded.
DECLARE @Xml XML='<row>
<DeletedVal>
<row attribute1="value1" attribute2="value2"/>
</DeletedVal>
</row>';
SELECT x1.y.value('local-name(.)', 'VARCHAR(30)') AS [Key]
, x1.y.value('.', 'VARCHAR(MAX)') AS [Value]
FROM @Xml.nodes('/row/DeletedVal//@*') x1(y)
Output:
Key Value
------------------------------ ------
attribute1 value1
attribute2 value2
The following OPENXML approach needs fixing, where I am not sure how to get the attributes.
DECLARE @DocHandle INT
EXEC sp_xml_preparedocument
@DocHandle OUTPUT
, @Xml;
SELECT *
FROM OPENXML (@docHandle, N'/row/DeletedVal//@*')
WITH ([Key] VARCHAR(10) 'key' --- This line needs editing
, [Value] VARCHAR(10) '.')
EXEC Sp_xml_removedocument
@DocHandle;
Output:
Key Value
---------- ----------
NULL value1
NULL value2