Solved

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

Posted on 2015-01-14
2
445 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
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.
How to create a custom search shortcut to site-search Experts Exchange using Google in the Firefox browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch your Bookmark Menu: Press 'Ctrl +…

840 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