2013-07-17 77 views
3

我的XML看起來像選擇值了XML的使用SQL Server 2008的命名空間

<p:initiateTest xmlns:S52="https://collaborate.com/svn/edm/tdp/CharacteristicEnumerations" 
    xmlns:p="http://collaborate.com/svn/capabilities/tdp/ManageNetworkAndServiceDiagnosticsV4/" 
    xmlns:p1="http://wsi.nat.com/2005/06/StandardHeader/" 
    xmlns:p2="https://collaborate.com/svn/edm/tdp/Test" 
    xmlns:p3="https://collaborate.com/svn/edm/tdp/Parties" 
    xmlns:p4="https://collaborate.com/svn/edm/tdp/MORT" > 
    <p1:standardHeader> 
     <p1:stateCode>OK</p1:stateCode> 
    </p1:standardHeader> 
</p:initiateTest> 

當我運行TSQL下方完成,但不會返回statecode值

Declare @mxml XML 

Select @mxml = xmlString 
From CT_GTCS_Temp_XML 
Where ID = 1 

;WITH XMLNAMESPACES( 'p' AS p, 'p1' as p1, 'p2' AS p2) 

select feed.xx.value('.','VARCHAR(MAX)') as statecode 
from @mxml.nodes('//p:initiateTest/p1:standardHeader/p1:stateCode') feed(xx) 

回答

5

您需要定義名稱空間 - 不是前綴! - 在您的WITH XMLNAMESPACES聲明中。

試試這個:

;WITH XMLNAMESPACES 
    ('http://collaborate.com/svn/capabilities/tdp/ManageNetworkAndServiceDiagnosticsV4/' AS p, 
    'http://wsi.nat.com/2005/06/StandardHeader/' as p1) 
select 
    feed.xx.value('.','VARCHAR(MAX)') as statecode 
from 
    @mxml.nodes('/p:initiateTest/p1:standardHeader/p1:stateCode') feed(xx) 
+1

由於現在這對我的作品 –