Solved

Parse XML Response Data with VBA????

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

737 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