Solved

How to read the XML data returned from an API with VB Script?

Posted on 2015-01-14
2
315 Views
Last Modified: 2015-01-14
I am trying to learn a bit more about VB scripting, as well as better understand how a client would use a simple API I have parked at a web site I own and have hosted at a cloud server.  I can successfully access the URL (no credentials needed at this point) and properly submit the requested fields and operand.  What comes back is a bunch of API text to my monitor.  I need to know how to capture the stream without it being displayed, and then use the saved page of XML lines as TXT so that I can have my script then pick off what I want and present it in a MSGBOX.

Here is what successfully accesses it:

  Set oShell = CreateObject("Wscript.Shell")
  oShell.Exec "C:\Program Files\Internet Explorer\iexplore.exe https://api.niftywebsite.net/?opts=WORD1&whatiwant=123456"

Here is what I get back in my browser:

<?xml version="1.0" encoding="UTF-8"?>
-<response>
-<entity>
<whatiwant>123456</whatiwant>
<WORD1>Just some test stuff</WORDS1>
</entity>
</response>

So can I suppress the monitor echo and pipe the XML text to a file?  Better would be if I could just hold the text and access it without a file save / open / read.
0
Comment
Question by:Mike Caldwell
2 Comments
 
LVL 20

Accepted Solution

by:
ltlbearand3 earned 500 total points
ID: 40550548
I would use the HTTP object and the xml Dom Document to get the values and parse them.

Something like this:

Dim objHttp, objXMLDoc

Set objHttp = CreateObject("MSXML2.ServerXMLHTTP.6.0")
Set objXMLDoc = CreateObject("Msxml2.DOMDocument") 

With objHttp
	.Open "GET", "https://api.niftywebsite.net/?opts=WORD1&whatiwant=123456"
	.Send
	objXMLDoc.LoadXML .responseText
End With

msgbox objXMLDoc.SelectSingleNode("//whatiwant").text

set objHttp = nothing
set objXMLDoc = nothing

Open in new window

0
 
LVL 1

Author Comment

by:Mike Caldwell
ID: 40550600
Perfect!  Exactly what I was looking for.  I frankly don't understand all of the code, but I'll let Mr. Google teach me the details.  Thanks so much.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article offers some helpful and general tips for safe browsing and online shopping. It offers simple and manageable procedures that help to ensure the safety of one's personal information and the security of any devices.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Google currently has a new report that is in beta and coming soon to Webmaster Tool accounts. This Micro Tutorial will highlight new features for Google Webmaster Tools.
This Micro Tutorial will demonstrate how nuggets on the Web are formatted by using Chrome Developer Tools. These tools would not only view the site's CSS but it can also modify it and save the CSS to use on your own site.

760 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

16 Experts available now in Live!

Get 1:1 Help Now