Solved

Parsing XML

Posted on 2013-11-26
1
299 Views
Last Modified: 2013-11-26
I am receiving an xml response as shown.  How do I get the SubscriptionId value from the xml?

<code>

Dim post_response As String, mmsg As String, subid As String


        post_response = "<?xml version=""1.0"" encoding=""utf-8""?><ARBCreateSubscriptionResponse xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns=""AnetApi/xml/v1/schema/AnetApiSchema.xsd"">"
        post_response &= "<refId>6290</refId>"
        post_response &= "<messages>"
        post_response &= "<resultCode>Ok</resultCode>"
        post_response &= "<message>"
        post_response &= "<code>I00001</code>"
        post_response &= "<text>Successful.</text>"
        post_response &= "</message>"
        post_response &= "</messages>"
        post_response &= "<subscriptionId>1893589</subscriptionId>"
        post_response &= "</ARBCreateSubscriptionResponse>"



        BookingXML.LoadXml(post_response)

            mmsg = BookingXML.ChildNodes(1).Item("messages").FirstChild.ChildNodes(0).InnerText
           
            If UCase(mmsg) = "OK" Then
                subid = ??
            End If

</code>
0
Comment
Question by:john
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 18

Accepted Solution

by:
zc2 earned 500 total points
ID: 39678491
I consider that ChildNodes traversing very unreliable.
Try to use the XPath selection, it's much more convenient.

Dim nsmgr As New XmlNamespaceManager(BookingXML.NameTable)
nsmgr.AddNamespace("anet", "AnetApi/xml/v1/schema/AnetApiSchema.xsd")
subid = BookingXML.SelectSingleNode("//anet:subscriptionId", nsmgr).InnerText

Open in new window

0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question