Link to home
Start Free TrialLog in
Avatar of JMO9966
JMO9966

asked on

VB.Net XML document retrieve string function ?

Hello,

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="http://www.w3.org/2001/XMLSchema-instance">
<JBXMLRespond>
<JobAddRs ErrorCode="0" Message="">
<ID>3550</ID>
<LastUpdated>2007-08-06T14:13:28</LastUpdated>

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.
                xmlResponseDoc.LoadXml(response)
                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?

Thanks,
JMO9966
Avatar of PaulHews
PaulHews
Flag of Canada image

Will that document have more than one JobAddRs node that you have to parse?
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
        Debug.WriteLine(xmlNode.Attributes("Message").Value)
    End If
Next
Avatar of JMO9966
JMO9966

ASKER

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

I will try that code right now.

Thanks again,
JMO9966
ASKER CERTIFIED SOLUTION
Avatar of PaulHews
PaulHews
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial