从 xml 结果 google 张中导入 xml

importxml from xml result google sheets

我正在尝试从中检索旅行距离和旅行时间 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

我试过TEXTJOIN(",",FALSE,IMPORTXML(E9,"//*")) 但很难提取,所以任何帮助分配和提取旅行距离和时间 在 excel 中使用 webservice 和 filterxml 工作正常但在 google 工作表中我找不到解决方案

以及 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>```

我相信你的目标如下。

  • i'm trying to retrieve travel distance and travel time from this XML URL 开始,您想使用 IMPORTXML.
  • 从 XML 数据中检索 TravelDistanceTravelDuration 的值

在这种情况下,下面的示例公式如何?

示例公式:

=IMPORTXML(A1,"//*[local-name()='TravelDistance' or local-name()='TravelDuration']")
  • 在这种情况下,单元格“A1”的 URL 显示在您的问题中。

结果:

  • 例如,当您要检索列的值时,请使用 TRANSPOSE,如 =TRANSPOSE(IMPORTXML(A1,"//*[local-name()='TravelDistance' or local-name()='TravelDuration']"))