2009-06-28 9 views
0

次のコードのxmlns属性は、必要な値を取得するのを止めます。 xmlnsではなく他の属性でも正常に動作します。私は与えられたxmlを制御できません - どうすればCrpIdの値を取得できますか?要素にxmlns属性があるときにopenxmlから値を取得できません

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 

答えて

0

は、私は全く自分自身をOpenXMLのを知らないが、this FAQは答えを持っているようです。基本的には、(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 
関連する問題