Solved

Parse XML Response Data with VBA????

Posted on 2008-06-18
5
915 Views
Last Modified: 2010-04-21
I have the following XML response after making a post to a URL.  I am trying to write a VBA function that will get the NodeValue of the <soap:Text ...>  node which is basically the error message to display in a message box.

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><soap:Code><soap:Value>soap:Receiver</soap:Value></soap:Code><soap:Reason><soap:Text xml:lang="en">Server was unable to process request. ---&gt; Data at the root level is invalid. Line 1, position 1.</soap:Text></soap:Reason><soap:Detail /></soap:Fault></soap:Body></soap:Envelope>


The function I have so far is ...

Function XMLParser(strXML)
Dim xmlDoc As New DOMDocument
Dim currNode As IXMLDOMNode
Dim rootNode As IXMLDOMNode
Dim oNodeList As IXMLDOMNodeList
Dim strResponseTxt As String
Dim x As Variant

xmlDoc.loadXML (strXML)
Set rootNode = xmlDoc.documentElement
strResponseTxt = xmlDoc.documentElement.selectSingleNode(rootNode.nodeName & "/soap:Text").NodeValue

End Function

I get an error on the strResponseTxt  = ........  line that says "Object variable or with block variable not set"

Any help will be appreciated.

ET


0
Comment
Question by:Eric Sherman
  • 2
  • 2
5 Comments
 
LVL 38

Expert Comment

by:puppydogbuddy
ID: 21819398
Hi ET,
Just a guess based on similar experiences with other objexts in Access.  You are assigning an object related expression to a string.  Try the CStr function to convert the expression to a string before the assignment..  

strResponseTxt = CStr(xmlDoc.documentElement.selectSingleNode(rootNode.nodeName & "/soap:Text").NodeValue)
0
 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 500 total points
ID: 21821521
etsherman,

  This is not a direct response to your question, but I believe it will be helpful.  Take a lookat the following:

http://www.experts-exchange.com/Microsoft/Development/MS_Access/Access_Coding-Macros/Q_23352134.html

  Towards the bottom of that thread is a comment I made with a link to an easy 123 understanding XML and some sample code.  Harfang also posted some code in that thread and I gave a sample in the last comment or so.

  In additional, when trying to understand how to load XML, the bext technique I found was to put a break in the code after it was loaded, then call up the immeadiate window.  From there, I explored the XML structure by using debug.Print <statement>  and was able to figure out what was valid when and how.

  The other thing you can do when execution is stopped is hover over a reference (before the line executes) and tell what portion of your statement the error is refering to.  My guess it is the .SelectSingleNode that is causing the problem.

HTH,
JimD
0
 
LVL 19

Author Closing Comment

by:Eric Sherman
ID: 31468667
Thanks all for the replies.  JDettman, much appreciated.  This points me in the right direction.

ET
0
 
LVL 57
ID: 21829836

  I know you've already accepted my comment as answer, but if you do get stuck on something please be sure to bounce back here with anything and I'll do my best to answer your questions directly.

JimD.
0
 
LVL 19

Author Comment

by:Eric Sherman
ID: 21831702
Ok, will do.


ET
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

757 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