I am thinking of working on an XML file in Visual Basic. When I tried it using DOMDOCUMENT
, Visual Basic is showing an error. It is not recognizing what DOCUMENT
is. Do I have to call a library to make it work? Take a look at my code:
Attribute VB_Name = "Module1"
Function getDistance(Origin As String, Destination As String) As Double
Dim HttpReq As Object
Dim myDomDoc As DOMDocument60
Dim distanceNode As IXMLDOMNode
Set HttpReq = CreateObject("MSXML2.XMLHTTP")
HttpReq.Open "GET", "http://maps.googleapis.com/maps/api/distancematrix/xml?origins=" & Origin & "&destinations=" & Destination & "&sensor=false", False
HttpReq.send
MsgBox HttpReq.responseText
Set myDomDoc = New DOMDocument60
myDomDoc.LoadXML HttpReq.responseText
Set distanceNode = myDomDoc.SelectSingleNode("/DistanceMatrixResponse/row/element/distance/value")
getDistance = distanceNode.Text / 1000
End Function
Project References:
Add
Imports System.Xml
to your imports listCreate a Variable similar to:
To load a document use:
To read nodes something similar to this should work:
etc...
Hope this is mildly useful