I have an excel spreadsheet where I have 25,000+ records with Lat/Lon coordinates and other data. I am trying to use an Excel VBA script to look up an associated County name based on the Lat/Lon using the following US Census web service link (an example coordinate included).
https://geo.fcc.gov/api/census/block/find?latitude=40.000&longitude=-90.000&format=xml
this returns the following response xml.
<Response status="OK" executionTime="0">
<Block FIPS="170179601002012" bbox="-90.013605,39.996144,-89.994837,40.010663"/>
<County FIPS="17017" name="Cass"/>
<State FIPS="17" code="IL" name="Illinois"/>
</Response>
The problem I have is that I need to access the "name" value (i.e.,'Cass', in this case) contained in County node, and this value will be copied into the Excel spreadsheet under the County column. Is there a way to access this value? The XML response is not in the standard form I would expect (I'm new to XML), <County>Cass</County> so I'm unsure how I would access the value I need from this returned response.
The whole XML connection and response part of the script seem to be working fine, I just need to know how get the values from the response for the node in question.
Here is what I have so far. Any help would be greatly appreciated. If you need the full code, let me know.
standard XML connection stuff here...
XmlResponse = oXMLHTTP.responseText
'Process the XML to get County name
strXML = XmlResponse
Set XDoc = New MSXML2.DOMDocument60
If Not XDoc.LoadXML(XmlResponse) Then
Err.Raise XDoc.parseError.ErrorCode, , XDoc.parseError.reason
End If
Set xNode = XDoc.SelectSingleNode("/Response/County")
MsgBox xNode.Text
'Insert County name into Excel
Cells(i + 2, 14).Value = xNode.Text
I am assuming that the xNode.Text part is where I need help in selecting the right part from the response (?).
Many thanks!