1

以下代码中的 xmlns 属性使我无法获得所需的值。适用于任何其他属性,但不适用于 xmlns。我无法控制给定的 xml - 如何获取 CrpId 值?

declare @CrpId int, @i int, @xml xml
set @xml = 
'<NewProgressReportResult xmlns="http://myDomain.com/crp">
<CrpId>2160</CrpId>
</NewProgressReportResult>'

exec sp_xml_preparedocument @i output, @xml

select 
CrpId
from openxml (@i, 'NewProgressReportResult', 2)
with (  
    CrpId int 'CrpId'
)

exec sp_xml_removedocument @i
4

1 回答 1

0

我自己根本不了解 OpenXML,但这个常见问题解答似乎有答案。基本上这是因为您在特定命名空间中有元素(由于xlmns属性),因此您需要能够在查询中指定相同的命名空间。

将此转换为您的特定问题,我认为您想要:

declare @CrpId int, @i int, @xml xml
set @xml = 
'<NewProgressReportResult xmlns="http://myDomain.com/crp">
<CrpId>2160</CrpId>
</NewProgressReportResult>'

set @ns = '<root xmlns:ns="http://myDomain.com/crp"/>

exec sp_xml_preparedocument @i output, @xml, @ns

select 
CrpId
from openxml (@i, '[ns:NewProgressReportResult]', 2)
with (  
        [ns:CrpId] int 'CrpId'
)

exec sp_xml_removedocument @i
于 2009-06-28T15:23:57.713 回答