?
Solved

VB.Net XML document retrieve string function ?

Posted on 2007-08-06
4
Medium Priority
?
420 Views
Last Modified: 2010-04-23
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
0
Comment
Question by:JMO9966
  • 3
4 Comments
 
LVL 38

Expert Comment

by:PaulHews
ID: 19641046
Will that document have more than one JobAddRs node that you have to parse?
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 19641119
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
0
 

Author Comment

by:JMO9966
ID: 19641174
Thanks Paul, the document will always contain one JobAddRs node.

I will try that code right now.

Thanks again,
JMO9966
0
 
LVL 38

Accepted Solution

by:
PaulHews earned 1000 total points
ID: 19641457
>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
    Debug.WriteLine(xmlNoded.Attributes("Message").Value)
End If

But either should get the job done.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses
Course of the Month13 days, 15 hours left to enroll

807 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