VBA Get XML node value

VBA to get XML node value from a HTML call returning XML.  The example below uses the Zillow API to return XML and extracts the zpid node value from the XML response.  Change “zpid” with the name of the node your trying to grab.

‘Enable below reference libraries.

‘Microsoft HTML Object Library
‘Microsoft XML v3.0

 

'VBA Code
 Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
 Url = http://www.zillow.com/webservice/GetSearchResults.htm?zws-id=X1-ZWz1g14y0hebyj_6h6e1&address=141+2nd+Ave+404&citystatezip=84103
 objHTTP.Open "GET", Url, False
objHTTP.send ("")
 SourceHTMLText = objHTTP.responseText

 SourceHTMLText = objHTTP.responseXML.getElementsByTagName("zpid")(0).FirstChild.NodeValue

Example of XML response:

http://www.zillow.com/webservice/GetSearchResults.htm?zws-id=X1-ZWz1g14y0hebyj_6h6e1&address=141+2nd+Ave+404&citystatezip=84103

<?xml version="1.0" encoding="UTF-8"?>
-<SearchResults:searchresults xmlns:SearchResults="http://www.zillow.com/static/xsd/SearchResults.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.zillow.com/static/xsd/SearchResults.xsd https://www.zillowstatic.com/vstatic/6ce354c/static/xsd/SearchResults.xsd">
<!-- H:011 T:18ms S:1517 R:Mon Jan 01 14:05:45 PST 2018 B:5.0.51000.3-hotfix_2017-12-26_fecb01c.3f62b94~hotfix-platform-for-2017-12-26.2e7029f -->
-<request>
<address>141 2nd Ave 404</address>
<citystatezip>84103</citystatezip>
</request>
+<message>
-<response>
-<results>
-<result>
<zpid>12719246</zpid>

Interested in learning new skills?