The following code snippet works:
The following code does not work:
The only difference is the attribute xmlns=" Why is this attribute causing the X-Path expressions to fail?
Code:
DECLARE @Response XML
SET @Response =
'<soap:Envelope xmlns:soap="[URL unfurl="true"]http://schemas.xmlsoap.org/soap/envelope/"[/URL] xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"[/URL] xmlns:xsd="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema">[/URL]
<soap:Body>
<ProcessUWResponse>
<OverallResult>Failure</OverallResult>
<Result>Failure</Result>
</ProcessUWResponse>
</soap:Body>
</soap:Envelope>'
SELECT
row.value('(//OverallResult)[1]', 'VARCHAR(20)') as Result1,
row.value('(//Result)[1]', 'VARCHAR(20)') as Result2
FROM @Response.nodes('.') AS T(row)
Result1 Result2
------- -------
Failure Failure
Code:
DECLARE @Response XML
SET @Response =
'<soap:Envelope xmlns:soap="[URL unfurl="true"]http://schemas.xmlsoap.org/soap/envelope/"[/URL] xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"[/URL] xmlns:xsd="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema">[/URL]
<soap:Body>
<ProcessUWResponse xmlns="[URL unfurl="true"]http://rebusis.com/webservices/gcs/IntegrationService">[/URL]
<OverallResult>Failure</OverallResult>
<Result>Failure</Result>
</ProcessUWResponse>
</soap:Body>
</soap:Envelope>'
SELECT
row.value('(//OverallResult)[1]', 'VARCHAR(20)') as Result1,
row.value('(//Result)[1]', 'VARCHAR(20)') as Result2
FROM @Response.nodes('.') AS T(row)
Result1 Result2
------- -------
Null Null