我正在尝试迭代以下soap响应以获取所有单独的eagResponse.text
值。下面的代码没有返回任何值。
declare @ws_response_xml varchar(max)
set @ws_response_xml='<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<noppSendSmsMessageResponse xmlns="http://nopp.att.com/noppsendsmsmessageservice" xmlns:ns2="http://cio.att.com/commonheader/v3">
<ResponseMessage>
<ResultSet>
<msgID>31891324</msgID>
<sender>AA5555</sender>
<recipient>BB5555</recipient>
<phoneNbr>2222222222</phoneNbr>
<message>test for backend ws call</message>
<appName>notifications.gui</appName>
<appLogID>TEST9999</appLogID>
<response>inserted</response>
<recptFlag>false</recptFlag>
<errorFlag>false</errorFlag>
<queueFlag>false</queueFlag>
<eagResponse>Successful Send - SMSA9B1FD59AA82D7D9</eagResponse>
</ResultSet>
<ResultSet>
<msgID>31891325</msgID>
<sender>AA5555</sender>
<recipient>ZZ5555</recipient>
<phoneNbr>5555555555</phoneNbr>
<message>test for backend ws call</message>
<appName>notifications.gui</appName>
<appLogID>TEST9999</appLogID>
<response>inserted</response>
<recptFlag>false</recptFlag>
<errorFlag>false</errorFlag>
<queueFlag>false</queueFlag>
<eagResponse>Successful Send - SMSA9B63633F2476291</eagResponse>
</ResultSet>
</ResponseMessage>
<inputEcho>BB5555;ZZ5555 - AA5555 - test for backend ws call - notifications.gui - TEST9999</inputEcho>
</noppSendSmsMessageResponse>
</soap:Body>
&#39;
declare @x as xml
set @x=@ws_response_xml;with xmlnamespaces('http://schemas.xmlsoap.org/soap/envelope/' as [soap]
,'http://nopp.att.com/noppsendsmsmessageservice' as nopp
,'http://cio.att.com/commonheader/v3' as ns2)
select s.c.value('(text())[1]','nvarchar(max)') as eagResponse
from @x.nodes('/soap:Envelope/soap:Body/noppSendSmsMessageResponse/ResponseMessage') as m(c)
outer apply m.c.nodes('/ResultSet/eagResponse') as s(c)
答案 0 :(得分:0)
想通了:
解决方案:选择应写成如下:(不需要外部联接,因为我没有引入任何顶级数据)
select m.c.value('nopp:eagResponse[1]','varchar(max)') as eagResponse
from @x.nodes('//soap:Envelope/soap:Body/nopp:noppSendSmsMessageResponse/nopp:ResponseMessage/nopp:ResultSet') as m(c)