- Bohack - https://www.bohack.com -

Query and Parse XML from VBScript

Toying around I needed to query XML from VBScript and parse it out for only the elements I needed. So I wrote a VBScript and figured I would share it. Many posts out there just load a file rather than a URL, this script will do both and I simplified it a bit.

The script here will basically query the URL and parse it our for the element name of description. Find a sitemap for a site and change the URL line like (http://somewhere.com/gsitemap.xml) and then change the xmltag to “loc”.

url = "http://news.google.com/news?hl=en&tab=wn&ned=us&q=test&ie=UTF-8&nolr=1&output=rss"
xmltag = "description"

set xmlDoc = createobject("Microsoft.XMLDOM")
xmlDoc.async = "false"
xmlDoc.load (url)

set xmlCol = xmldoc.getElementsByTagName(xmltag)

For Each Elem In xmlCol

WScript.Echo "XML Element Count :" & xmlCol.length

Set xmlCol = Nothing
Set xmlDoc = Nothing