Solved

Parsing XML

Posted on 2013-11-26
1
287 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
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now