Solved

All I want is to retrieve 3 values from an XML return from a web service

Posted on 2007-11-28
2
205 Views
Last Modified: 2012-08-14
All I need to get from this return is
messages/resultCode,
messages/message/text
ARBCreateSubscriptionResponse/subscriptionId

I can parse using substring but this is (supposedly)  the hard way. How do I use XmlDocument to grab JUST those values?

Ive tried
Dim sMsgList As XmlNodeList = oXMLDoc.GetElementsByTagName("messages"),
and I get an invalid characters error ...

I've tried stepping through child nodes (but I can't seem to get to 'messages/message/text ')

so after 5 hours of trying different things with mixed results, I asking the experts. PLEASE do not send me to links; I googled 'parse xmldocument +VB.net' and 'read xmldocument +VB.net' and other iterations of search and have looked at about 30 of them.


<?xml version="1.0" encoding="utf-8"?>
<ARBCreateSubscriptionResponse xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
  <refId>Sample</refId>
  <messages>
    <resultCode>Ok</resultCode>
    <message>
      <code>I00001</code>
      <text>Successful.</text>
    </message>
  </messages>
  <subscriptionId>100748</subscriptionId>
</ARBCreateSubscriptionResponse>

Open in new window

0
Comment
Question by:LyndaPostal
[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
2 Comments
 
LVL 38

Accepted Solution

by:
PaulHews earned 500 total points
ID: 20367703
Sample code:  It's complicated a bit by the default namespace.
Imports System.Xml
 
Public Class Form1
 
 
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim xmlDoc As New XmlDocument
        xmlDoc.Load("C:\temp\test.xml")
        xmlDoc.PreserveWhitespace = True
 
        Dim nsMgr As New XmlNamespaceManager(xmlDoc.NameTable)
        nsMgr.AddNamespace("ns", "AnetApi/xml/v1/schema/AnetApiSchema.xsd")
 
        Dim Path() As String = {"messages/resultCode", "messages/message/text", "subscriptionId"}
        For i As Integer = 0 To Path.GetUpperBound(0)
            Dim node As XmlNode = xmlDoc.DocumentElement.SelectSingleNode("//ns:" & Path(i).Replace("/", "/ns:"), nsMgr)
            If Not node Is Nothing Then
                Debug.WriteLine(node.InnerText)
            End If
        Next
    End Sub
End Class

Open in new window

0
 

Author Closing Comment

by:LyndaPostal
ID: 31411486
and I thank you so much. It works perfectly! So I can understand what you did and why it worked: ... Where can I find out more about 'default namespace' and XML? So many (maybe all??) web service returns use them? A link would be great.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

688 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