Solved

Parse XML Response Data with VBA????

Posted on 2008-06-18
5
957 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

820 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