VBA XML SelectNodes Issue


Hi All,

Please help me out with this code snippet. I am here in trouble with "SelectNodes". Whenever I am using "SelectSingleNode", the code is fetching me results but when I am using SelectNodes in place of SelectSingleNode the code is throwing me 0 (nothing). Please suggest what to do.

I am new to VBA and have written this code with lots of googling about syntaxes and datatypes. Please correct if anywhere wrong and tell me what I am missing.

Function UserPlaces(Origin As String) As String
Dim himRequest As XMLHTTP60
Dim himDomDoc As DOMDocument60
Dim nodeList As IXMLDOMNode
 
UserPlaces = 0

On Error GoTo exitRoute

Origin = Replace(Origin, " ", "%20")

Set himRequest = New XMLHTTP60
himRequest.Open "GET", "https://maps.googleapis.com/maps/api/place/nearbysearch/xml?location=" _
& Origin & "&radius=5000&types=food&sensor=false&key=YOUR KEY HERE", False
himRequest.send
Set himDomDoc = New DOMDocument60
himDomDoc.LoadXML himRequest.responseText


Set nodeList = himDomDoc.SelectSingleNode("//result/vicinity")

If Not nodeList Is Nothing Then UserPlaces = nodeList.Text

 
exitRoute:
Set nodeList = Nothing
Set himDomDoc = Nothing
Set himRequest = Nothing

End Function

July 22nd, 2013 2:22am

HI,

Remove "Set" in the code "Set nodeList = himDomDoc.SelectSingleNode("//result/vicinity")" to check the issue.

Refer to the following link:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms757846(v=vs.85).aspx

Free Windows Admin Tool Kit Click here and download it now
July 23rd, 2013 12:23am

Nodelist

I think you wanted the above variable to contain collection of nodes.If that is the case,declare as

Dim nodeList As IXMLDOMNodeList

IXMLDOMNodeList is a collection of nodes.Even if it contains only one node). IXMLDOMNode is a node.

Selectnodes is required where you expect nodelist and selectsinglenode where you expect a node.

July 26th, 2013 10:46am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics