经典ASP读取XML值

时间:2013-04-15 14:12:54

标签: xml asp-classic

我尝试使用google maps api定义2点之间的行车距离。它返回一个XML,我将其加载到XMLDOM对象中。但是我无法在任何地方找到如何在孩子的孩子中获得孩子的价值...我已经阅读了Microsoft教程,但它没有显示如何从XML中检索值

示例XML是:

<DistanceMatrixResponse>
<status>OK</status>
<origin_address>Gentsesteenweg 5, 9200 Dendermonde, België</origin_address>
<destination_address>Veerstraat 39, 9200 Dendermonde, België</destination_address>
<row>
    <element>
        <status>OK</status>
        <duration>
            <value>117</value>
            <text>2 min.</text>
        </duration>
        <distance>
            <value>1061</value>
            <text>1,1 km</text>
        </distance>
    </element>
</row>
</DistanceMatrixResponse>

我的代码部分是:

Set XmlObj = Server.CreateObject("Microsoft.XMLHTTP")
strURL = "http://maps.googleapis.com/maps/api/distancematrix/xml?origins=" & dblFromLatitude & "+" & dblFromLongitude & "&destinations=" & dblToLatitude & "+" & dblToLongitude & "&mode=driving&language=" & strLanguage & "&sensor=false"
'DebugFile strURL
XmlObj.Open "POST", strURL, false
XmlObj.send      
strResponse = XmlObj.responseText
Set XmlObj = Nothing


Set xmlLongLat = Server.CreateObject("Microsoft.XMLDOM")
xmlLongLat.async=false
xmlLongLat.loadXML(strResponse)

If Not xmlLongLat.GetElementsByTagName("DistanceMatrixResponse")(0).ChildNodes(0).GetElementsByTagName("row")(0).ChildNodes(0).GetElementsByTagName("element")(0).ChildNodes(0).GetElementsByTagName("distance")(0).ChildNodes(0) Is Nothing Then

    dblDrivingDistance = Round(CDbl(Nz(xxmlLongLat.GetElementsByTagName("DistanceMatrixResponse")(0).ChildNodes(0).GetElementsByTagName("row")(0).ChildNodes(0).GetElementsByTagName("element")(0).ChildNodes(0).GetElementsByTagName("distance")(0).ChildNodes(0).NodeValue, 0))/1000,2)
Else 'xmlLongLat.GetElementsByTagName("element")(0) Is Nothing Then
    dblDrivingDistance = 0
    DebugFile "fgfzefzef"
End If 'xmlLongLat.GetElementsByTagName("element")(0) Is Nothing Then

Set xmlLongLat = Nothing    

我希望得到&#34;价值&#34; &#34;距离&#34;但是,尽管已经尝试了所有的事情,但我似乎并没有成功

1 个答案:

答案 0 :(得分:0)

xmlDoc.setProperty "SelectionLanguage", "XPath"
node = xmlDoc.selectSingleNode("/row/elelemnt/distance/value").innerText

或类似 - 使用XPath