对于以下.nodes()方法,我需要一个等效的OPENXML方法。属性会有所不同,不能硬编码。
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)
输出:
Key Value
------------------------------ ------
attribute1 value1
attribute2 value2
以下OPENXML方法需要修复,我不确定如何获取属性。
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;
输出:
Key Value
---------- ----------
NULL value1
NULL value2