VB.Net XML document retrieve string function ?

Posted on 2007-08-06
Last Modified: 2010-04-23

I'm using VB.Net to create an XML document that get's sent to an import program.

The import program will send me a ressponse back in this format:

'liine of code to generate response doc
strResponseDoc = xmlResponseDoc.OuterXml

'contents of strResponseDoc:

<JBXML xmlns:xsi="">
<JobAddRs ErrorCode="0" Message="">

What I'm looking do to with VB is retrieve the message returned in double quotes on the third line of this sample response document, it there is an ErrorCode <> 0 there will be an error in this string that I need to retrieve.

Here's more of my code if needed.

strXmlRequestDoc = xmlRequestDoc.OuterXml

                'Send XML to Import
                response = jb.ProcessRequest(strXmlRequestDoc)
                xmlResponseDoc = New XmlDocument
                xmlRequestDoc = Nothing

                'Set ID to the new job's ID.
                strResponseDoc = xmlResponseDoc.OuterXml

As you can see strResponseDoc is where I need to retrieve this error messagef from.

Does VB have a way of doing so or will I need to create a function?

Question by:JMO9966
    LVL 38

    Expert Comment

    Will that document have more than one JobAddRs node that you have to parse?
    LVL 38

    Expert Comment

    I'm going to assume yes, because it doesn't make much difference to the code...

    For Each xmlNode As XmlNode In xmlResponseDoc.SelectNodes("//JobAddRs")
        If CInt(xmlNode.Attributes("ErrorCode").Value) <> 0 Then
        End If

    Author Comment

    Thanks Paul, the document will always contain one JobAddRs node.

    I will try that code right now.

    Thanks again,
    LVL 38

    Accepted Solution

    >Thanks Paul, the document will always contain one JobAddRs node.

    If it's one and only one, instead of at least one, then you can SelectSingleNode instead:

    Dim xmlNoded As XmlNode = xmlResponseDoc.SelectSingleNode("//JobAddRs")
    If CInt(xmlNoded.Attributes("ErrorCode").Value) <> 0 Then
    End If

    But either should get the job done.

    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

    Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    746 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

    14 Experts available now in Live!

    Get 1:1 Help Now