我正在考虑在 Visual Basic 中处理 xml 文件。当我使用 DOMDOCUMENT visual basic 尝试它时显示错误。它无法识别 domdocument 是什么。我是否必须调用任何库才能使其正常工作。看看我的代码
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