Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Parse XML Response Data with VBA????

Posted on 2008-06-18
5
Medium Priority
?
1,098 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 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
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…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

963 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