Reputation: 43
Using the following XML document:
I want to get the value "360050216022002"
from the node:
<block FIPS="360050216022002">
Here is the code in VBA, but the number is not in a node so I cannot use
SelectNodes
.
How can I change the code?
Function GetCensusTrack(lat As String, lon As String) As String
' Requires a reference to Microsoft XML, v6.0'
Dim myRequest As XMLHTTP60
Dim blockNode As IXMLDOMNode ' Can I set it as Node?'
Dim uu As String
Set myRequest = New XMLHTTP60
uu = "http://www.broadbandmap.gov/broadbandmap/census/block?latitude=" & lat & "&longitude=" & lon & "&format=xml"
myRequest.Open "GET", uu, False
myRequest.send
If myRequest.readyState = 4 Then
Set myDomDoc = New DOMDocument60
myDomDoc.LoadXML myRequest.responseText
' Get the latitude and longitude node values'
' what should I type here?' Set blockNode = ???? End If End Function
Upvotes: 1
Views: 1065
Reputation: 16311
FIPS
is an attribute of <block>
. You can use @
to specify that you want to query an attribute:
Dim a As Object
Set a = myDomDoc.SelectSingleNode("/Response/Results/block/@FIPS")
If Not a Is Nothing Then
Debug.Print "Attribute value = " & a.Text
End If
Upvotes: 1