importxml from xml result google sheets

Viewed 148

i'm trying to retrieve travel distance and travel time from this XML URL :https://dev.virtualearth.net/REST/v1/Routes/DistanceMatrix?origins=30.90232,30.17693&destinations=31.10171,30.3131&travelMode=driving&o=xml&key=AngGTts45jKAUVLSgsymA4Vho1GJfd2PN5V11RenWFRjhfa5gRwexx5HSbNQYz-2

i tried to TEXTJOIN(",",FALSE,IMPORTXML(E9,"//*")) but hard to extract , so any help with this to allocate and extract Travel distance and time in excel using webservice and filterxml works fine but in google sheets i couldn't find solution

and this result for XML

<Copyright>Copyright © 2022 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.</Copyright>
<BrandLogoUri>http://dev.virtualearth.net/Branding/logo_powered_by.png</BrandLogoUri>
<StatusCode>200</StatusCode>
<StatusDescription>OK</StatusDescription>
<AuthenticationResultCode>ValidCredentials</AuthenticationResultCode>
<TraceId>8fb637a9728f4476837032284c19ea52|DU0000274E|0.0.0.0|DU0000049D</TraceId>
<ResourceSets>
<ResourceSet>
<EstimatedTotal>1</EstimatedTotal>
<Resources>
<Resource xsi:type="DistanceMatrix">
<Origins>
<Coordinate>
<Latitude>30.90232</Latitude>
<Longitude>30.17693</Longitude>
</Coordinate>
</Origins>
<Destinations>
<Coordinate>
<Latitude>31.10171</Latitude>
<Longitude>30.3131</Longitude>
</Coordinate>
</Destinations>
<Results>
<Distance>
<DepartureTime xsi:nil="true"/>
<OriginIndex>0</OriginIndex>
<DestinationIndex>0</DestinationIndex>
<TravelDistance>42.261</TravelDistance>
<TravelDuration>78.5</TravelDuration>
<TotalWalkDuration>0</TotalWalkDuration>
</Distance>
</Results>
</Resource>
</Resources>
</ResourceSet>
</ResourceSets>
</Response>```
1 Answers

I believe your goal is as follows.

  • From i'm trying to retrieve travel distance and travel time from this XML URL, you want to retrieve the values of TravelDistance and TravelDuration from the XML data using IMPORTXML.

In this case, how about the following sample formula?

Sample formula:

=IMPORTXML(A1,"//*[local-name()='TravelDistance' or local-name()='TravelDuration']")
  • In this case, the cell "A1" has the URL shown in your question.

Result:

enter image description here

  • For example, when you want to retrieve the values to the columns, please use TRANSPOSE like =TRANSPOSE(IMPORTXML(A1,"//*[local-name()='TravelDistance' or local-name()='TravelDuration']")).
Related