?
Solved

Parse XML Response Data with VBA????

Posted on 2008-06-18
5
Medium Priority
?
1,034 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 58

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 2000 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 58
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
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…
Suggested Courses

765 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