?
Solved

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

Posted on 2015-01-14
2
Medium Priority
?
450 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
[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 Comments
 
LVL 20

Accepted Solution

by:
ltlbearand3 earned 2000 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
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…
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…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

649 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