Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 435
  • Last Modified:

Access innerxml from XmlNode

I'm trying to access to DayOfWeek from the innerxml response.
Please see the screen shot for a better idea.

 Screen shot of debugger
0
JRockFL
Asked:
JRockFL
  • 3
  • 3
1 Solution
 
käµfm³d 👽Commented:
Why are you storing the return from CarrierPickupRequest() in a variable of type Object? It's apparent it's an XmlNode, so why not store it as such? Then you can use its methods to extract the data.
Dim result As System.Xml.XmlNode = service.CarrierPickupRequest(xmlString)

Dim response As System.Xml.XmlNode = result.SelectSingleNode("CarrierPickupRequestResponse")

Dim innerXml As String = response.InnerXml

Open in new window

0
 
JRockFLAuthor Commented:
Thank you for your reply. That was from an earlier screen shot and I have casted it to the correct type.

I'm still not able to access the element i need.

The result is actually an array of XmlNode

        Dim result As System.Xml.XmlNode() = CType(service.CarrierPickupRequest(xmlString), System.Xml.XmlNode())
        Dim innerXml As String = String.Empty

        For Each node As System.Xml.XmlNode In result
            Dim response As System.Xml.XmlNode = node.SelectSingleNode("//CarrierPickupResponse/Response/ConfirmationNumber")
            If Not response Is Nothing Then
                innerXml = response.InnerXml
                Exit For
            End If
        Next

Here is an example response from the API
<?xml version="1.0" encoding="UTF-8"?> <CarrierPickupResponse> <AccountID></AccountID> <ErrorMsg></ErrorMsg> <Test></Test> <Response> <DayOfWeek></DayOfWeek> <Date></Date> <CarrierRoute></CarrierRoute> <ConfirmationNumber></ConfirmationNumber> </Response> </CarrierPickupResponse>
0
 
käµfm³d 👽Commented:
The result is actually an array of XmlNode
Indeed it is. I missed the parens in the SS  = )

Try the XPath:
Dim response As System.Xml.XmlNode = node.SelectSingleNode("Response/ConfirmationNumber")

Open in new window

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
JRockFLAuthor Commented:
That would perfectly, thank you so much.
0
 
käµfm³d 👽Commented:
NP. Glad to help.

For future reference, the reason why yours didn't work is because at the point of calling SelectSingleNode, you were already at CarrierPickupResponse, and so you were trying to find a CarrierPickupResponse that was under a CarrierPickupResponse, which of course doesn't exist.
0
 
JRockFLAuthor Commented:
Oh, ok, that makes sense now. Thank you.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now