0

i am thinking of working on xml file in visual basic. when i tried it using DOMDOCUMENT visual basic is showing error. It is not recognising what domdocument is. Do i have to call any library to make it working. 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
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
ruby007
  • 57
  • 2
  • 7

1 Answers1

0

Project References:

System.XML

Add Imports System.Xml to your imports list

Create a Variable similar to:

Dim MyXMLDoc As New XmlDocument

To load a document use:

 MyXMLDoc.Load("Document path here")

To read nodes something similar to this should work:

Dim Items as Xml.XmlNodeList = MyXMLDoc.SelectNodes("ParentNode/ChildNodes")
Dim Item as Xml.XmlNode
Try
  For Each Item in Items
    Dim randomstring As String = Item.GetAttributes.GetNamedItem("ItemName").value
  Next
Catch ex As Exception
End Try

etc...

Hope this is mildly useful

Ducklz
  • 11
  • 1