Search Google using Microsoft Soap Toolkit 2.0 and JScript


Background

Basically there is nothing new besides everything posted already on this topic. I just found it hard to find any info on how to use high level API of the MS Soap Toolkit 2.0 when there is a complex message returned in response to a SOAP call
And on the other hand there was not a good example on how to solve several problems with processing the result returned from Google.



The Environment

In fact I don't know which /if any/ version of Windows comes with the Soap Toolkit installed. You can download it from here
The code snippet uses a XSL file that defines the transformation thet is to be performed over resultElements tree node from the response. That file can be found in the example HTA application


PLEASE NOTE IN ORDER TO USE THOSE EXAMPLES GO TO GOOGLE AND GET YOUR OWN GOOGLE KEY and then replace it in the code where GOOGLE_KEY is used



The WScript code snippet

//replace with your own
var GOOGLE_KEY = "xxxxxxxxxxxxxxxxx"
var WSDL_URL = "GoogleSearch.wsdl"

WScript.echo("Connecting: " + WSDL_URL)
var Google = WScript.CreateObject("MSSOAP.SoapClient") 
Google.mssoapinit(WSDL_URL, "", "", "")

hRes = Google.doGoogleSearch( 
	GOOGLE_KEY,
	"linux-bg",
	0,
	10,
	true,
	"",
	true,
	"",
	"",
	""
)

/*
	Returned from the search is a XMLDOMNodeList
*/

hRes.reset()
while( hNode = hRes.nextNode() )
{
	if( hNode.nodeName == "resultElements" ) break
}

hXslDoc = new ActiveXObject( "MSXML2.FreeThreadedDOMDocument" )
hXslDoc.async = false
hXslDoc.load( "google.xsl" )

hXslTemplate = new ActiveXObject( "MSXML2.XSLTemplate" )
hXslTemplate.stylesheet = hXslDoc

hProcessor = hXslTemplate.createProcessor()
hProcessor.input = hNode
hProcessor.transform()

WScript.echo( hNode.nodeName +' \n\n '+ hNode.nodeType +' \n\n '+ hNode.xml )
WScript.echo( hProcessor.output )



The Extras

I created a simple HTA Application that implements the Google search.
Download it here