【发布时间】:2014-07-14 22:31:44
【问题描述】:
我一直在使用Bing Maps API 来获取某个区域的交通事件。然后,这将创建一个 XML 文档,我可以访问作为单个节点的对象,但不能回显嵌套在其他节点中的任何节点。 XML 文档如下所示:
<Response xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://schemas.microsoft.com/search/local/ws/rest/v1">
<Copyright>
- Message -
</Copyright>
<BrandLogoUri>
- Logo -
</BrandLogoUri>
<StatusCode>200</StatusCode>
<StatusDescription>OK</StatusDescription>
<AuthenticationResultCode>ValidCredentials</AuthenticationResultCode>
<TraceId>
- Trace ID-
</TraceId>
<ResourceSets>
<ResourceSet>
<EstimatedTotal>1</EstimatedTotal>
<Resources>
<TrafficIncident>
<Point>
<Latitude> - Latitude - </Latitude>
<Longitude>- Longitude -</Longitude>
</Point>
<IncidentId>- IncidentId -</IncidentId>
<LastModifiedUTC>- Time -</LastModifiedUTC>
<StartTimeUTC>- Time -</StartTimeUTC>
<EndTimeUTC>- Time -</EndTimeUTC>
<Type>- Type -</Type>
<Severity>- Severity -</Severity>
<Verified>- True -</Verified>
<RoadClosed>- True -</RoadClosed>
<Description>
- Description -
</Description>
<ToPoint>
<Latitude>-Latitude -</Latitude>
<Longitude>- Longitude -</Longitude>
</ToPoint>
</TrafficIncident>
</Resources>
</ResourceSet>
</ResourceSets>
</Response>
为了在单个节点中回显对象,我一直在使用以下 PHP 代码:
<?php
$xml = simplexml_load_file("link");
echo "Trace Id <br>";
echo $xml->TraceId . "<br>";
echo $xml->Copyright . "<br>";
echo $xml->Verified . "<br>";
?>
为了回显嵌套节点中的纬度,我尝试了 PHP 代码:
foreach( $xml->TrafficIncident->Point->Latitude as $row ){
echo'<td>'.$row.'</td>';
}
但到目前为止还没有运气。有什么想法吗?
【问题讨论】:
-
你的错误信息是什么?
-
我认为你的 XML 路径是错误的,但如果没有代码格式很难说。