Avatar of Dale Fye
Dale Fye
Flag for United States of America asked on

Retrieve values from XML response to Google Maps

I'm pulling data from the Google Map API and it returns an XML response which looks like:
<DistanceMatrixResponse>
 <status>OK</status>
 <origin_address>Grafton, VA 23692, USA</origin_address>
 <destination_address>Yorktown, VA 23690, USA</destination_address>
 <row>
  <element>
   <status>OK</status>
   <duration>
    <value>556</value>
    <text>9 mins</text>
   </duration>
   <distance>
    <value>9779</value>
    <text>9.8 km</text>
   </distance>
  </element>
 </row>
</DistanceMatrixResponse>

Open in new window

I would like to extract the duration/text and distance/text values from this XML but the code found is using is not returning those values
    Dim domResponse As DOMDocument60
    Set domResponse = New DOMDocument60
    domResponse.loadXML objXMLHTTP.responseText
    
    Dim ixnStatus As Variant
    Set ixnStatus = domResponse.selectSingleNode("//status")
    
    If ixnStatus.Text = "OK" Then
        Dim ixnDistance, ixnDuration
        Set ixnDistance = domResponse.selectSingleNode("/DistanceMatrixResponse/row/element/distance/text")
Debug.Print ixnDistance
        Set ixnDuration = domResponse.selectSingleNode("/DistanceMatrixResponse/row/element/duration/text")
Debug.Print ixnDuration
    End If

Open in new window

and actually raises an error (#438          Object doesn't support this property or method) on line 11
I'm sure this is just a matter of getting the "SelectSingleNode" argument correct, but I have played with just about every combination of nodes names and cannot get this right.
XML

Avatar of undefined
Last Comment
zc2

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Dale Fye

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
zc2

I believe, the exception raised, because you trying to print out an object, not a string in
Debug.Print ixnDistance
try this instead:
if ixnDistance is Nothing then
   Debug.Print "No distance node!"
else
   Debug.Print ixnDistance.text
end if

Open in new window

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23