迭代xml值(wikimapia)

时间:2012-03-21 13:41:06

标签: php xml iteration

我试图通过实施他们的API从wikimapia网站上获取一些数据。当我尝试迭代值时,它只迭代“id”值。 请参阅下面的PHP代码以获取数据:

<?php

$url = ("http://api.wikimapia.org/?function=search&key=****&q=buildings&lat=51.5424&lon=-0.1734&count=20&page=1");

$xml = simplexml_load_file($url);

foreach ($xml->place as $entry) {

echo $entry->attributes()->id;
echo $entry->attributes()->name;
echo $entry->attributes()->url;
echo $entry->attributes()->lat;
echo $entry->attributes()->lon;

}
// Process XML file

?>

在下面找到网站上XML结构的摘录:

<?xml version="1.0" encoding="utf-8"?>
<?access-control allow="*"?>
<folder language="en" version="1.0" found="87" page="1" count="20">
<place id="18508464">
<name>Miles Buildings</name>
<url>http://wikimapia.org/18508464/Miles-Buildings</url>
<location>
<lon>-0.1703605</lon>
<lat>51.5211928</lat>
<north>51.5218053</north>
<south>51.5205803</south>
<east>-0.1696712</east>
<west>-0.1710498</west>
</location>
<polygon>
<point x="-0.1699769" y="51.5218053"/>
<point x="-0.1696712" y="51.5214648"/>
<point x="-0.1703846" y="51.5211177"/>
<point x="-0.1699823" y="51.5206971"/>
<point x="-0.1703203" y="51.5205803"/>
<point x="-0.1708031" y="51.5209341"/>
<point x="-0.1707333" y="51.5209741"/>
<point x="-0.1710498" y="51.5212812"/>
</polygon>
</place>
</folder>

我做错了什么? 感谢。

1 个答案:

答案 0 :(得分:0)

文件夹属性是:

language="en" version="1.0" found="87" page="1" count="20"

另一个是子节点,尝试使用print_r($xml);来查看你得到的内容