Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm successfully consuming a web-service SOAP envelope XML response. I've included a shortened version at the bottom.

(#1) when I use:
Dim totalcost1 As String = cfnroot.SelectNodes("GetRateQuoteResponse/GetRateQuoteResult/TotalCharges").Item(0).InnerText

I'm getting a value of 2597.01 which is correct.
(#2) When I use:
im totalcost As XmlElement = DirectCast(CFLxmldoc.SelectSingleNode("df:GetRateQuoteResponse/df:GetRateQuoteResult/df:TotalCharges", mgr), XmlElement)

I'm not getting a value at all.
I prefer to use #2's syntax and always have used it. I can't figure out why i'm not getting any value from #2. I find it easier to test for empty values or nodes that aren't present. This is my first time using a SOAP XML envelope. Normally use REST/URL.

<?xml version="1.0"?>
<SOAP-ENV:Body xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
  <GetRateQuoteResponse	xmlns="">
    <GetRateQuoteResult>
      <Date>03/22/2019</Date>
      <Time>12:06:22</Time>
      <DeficitAmount>152.84</DeficitAmount>
      <TotalCharges>2597.01</TotalCharges>
      <NetCharges>918.91</NetCharges>
     </GetRateQuoteResult>
  </GetRateQuoteResponse>
</SOAP-ENV:Body>


What I have tried:

Dim CFLresponse = CFLService.GetRateQuoteXml(CFLRaterequest)
Dim ResponseXML As String = CFLresponse.InnerXml
Dim CFLxmldoc As XmlDocument = New XmlDocument
CFLxmldoc.LoadXml(ResponseXML)

    Dim mgr As New XmlNamespaceManager(CFLxmldoc.NameTable)
mgr.AddNamespace("df", CFLxmldoc.DocumentElement.NamespaceURI)
Dim cfnroot As XmlElement = CFLxmldoc.DocumentElement

Dim totalcost As XmlElement = DirectCast(CFLxmldoc.SelectSingleNode("df:GetRateQuoteResponse/df:GetRateQuoteResult/df:TotalCharges", mgr), XmlElement)

Dim totalcost1 As String = cfnroot.SelectNodes("GetRateQuoteResponse/GetRateQuoteResult/TotalCharges").Item(0).InnerText
Posted
Updated 26-Mar-19 9:07am

1 solution

Two problems:

1) Your SelectSingleNode call starts from the document, whereas your SelectNodes call starts from the root node.

2) Your SelectSingleNode call is looking for nodes in the "http://schemas.xmlsoap.org/soap/envelope/" namespace, whereas your SelectNodes call is looking for nodes with no namespace.

Try:
Dim totalcost As XmlElement = DirectCast(cfnroot.SelectSingleNode("GetRateQuoteResponse/GetRateQuoteResult/TotalCharges"), XmlElement)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900