Solved

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

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
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.
Shows how to create a shortcut to site-search Experts Exchange using Google in the Chrome browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch the Search Engine Menu: In chrome, via you…

733 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