Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with XML nodes function 1

Status
Not open for further replies.

ddiamond

Programmer
Apr 22, 2005
918
0
0
US
The following code snippet works:
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
The following code does not work:
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
The only difference is the attribute xmlns=" Why is this attribute causing the X-Path expressions to fail?
 
try:

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('[!]declare default element namespace "[URL unfurl="true"]http://rebusis.com/webservices/gcs/IntegrationService";[/URL][/!](//OverallResult)[1]', 'VARCHAR(20)') as Result1,
  row.value('[!]declare default element namespace "[URL unfurl="true"]http://rebusis.com/webservices/gcs/IntegrationService";[/URL][/!](//Result)[1]', 'VARCHAR(20)') as Result2
FROM @Response.nodes('.') AS T(row)


-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
By the way.... nice question. The way you wrote the question and then code made it easy for us to help you.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
George,

You da'man. Your solution worked great!

- Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top