【发布时间】:2012-11-19 14:20:59
【问题描述】:
我正在尝试使用 PHP 调用 XML 数组,但无论出于何种原因,它都不能正确提供结果。 XML 看起来像这样一个 simpleXMLElement。
SimpleXMLElement 对象 ( [@attributes] => 数组 ( [版权] => 所有数据版权 2012。 )
[route] => SimpleXMLElement Object
(
[@attributes] => Array
(
[tag] => 385
[title] => 385-Sheppard East
[color] => ff0000
[oppositeColor] => ffffff
[latMin] => 43.7614499
[latMax] => 43.8091799
[lonMin] => -79.4111
[lonMax] => -79.17073
)
[stop] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[tag] => 14798
[title] => Sheppard Ave East At Yonge St (Yonge Station)
[lat] => 43.7614499
[lon] => -79.4111
[stopId] => 15028
)
)
[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[tag] => 4024
[title] => Sheppard Ave East At Doris Ave
[lat] => 43.7619499
[lon] => -79.40842
[stopId] => 13563
)
)
停止数组有几个部分。我的代码如下所示:
$url = "this_url";
$content = file_get_contents($url);
$xml = new SimpleXMLElement($content);
$route_array = $xml->route->stop;
当我打印 $route_array 时,它只显示来自站点的 1 条记录。我需要通过循环运行它吗?通常,当我在 JSON 中执行此操作时,它可以正常工作。我只想在停止数组中获取所有内容。
提前感谢所有帮助像我这样的初学者的专家
【问题讨论】: