Reputation: 300
I am using the following feed: http://feeds.livep2000.nl/
I try to parse it with the following line of code:
$xml = simplexml_load_string(file_get_contents($url), null, LIBXML_NOCDATA);
It shows me data like i expect but missing the geo:lat
and geo:long
like this:
XML
<item>
<title>
<![CDATA[
A2 (DIA: ) some title
]]>
</title>
<link>http://monitor.livep2000.nl?SPI=1707082033480217</link>
<pubDate>Sat, 08 Jul 2017 20:33:48 +0200</pubDate>
<description>
<![CDATA[
1420999 MKA Rotterdam-Rijnmond ( Monitorcode )<br/>1420029 MKA Rotterdam-Rijnmond ( Ambulance 17-129 )<br/>
]]>
</description>
<guid>1707082033480217</guid>
<author/>
<geo:lat>51.8431255</geo:lat>
<geo:long>4.3429498</geo:long>
</item>
Response
["item"]=>
array(50) {
[0]=>
object(SimpleXMLElement)#163 (6) {
["title"]=>
string(41) "some title"
["link"]=>
string(48) "http://monitor.livep2000.nl?SPI=1707082036240209"
["pubDate"]=>
string(31) "Sat, 08 Jul 2017 20:36:24 +0200"
["description"]=>
string(44) "description ( Ambulance 09-129 )"
["guid"]=>
string(16) "1707082036240209"
["author"]=>
object(SimpleXMLElement)#213 (0) {
}
}
etc....
Any idea why the geo nodes are missing?
Upvotes: 0
Views: 127
Reputation: 4021
The problem is that lat
and long
are a part of geo
namespace in the mentioned XML and simplexml
does not allow you to access them by default.
You need to use something like:
$ns = $xml->getNamespaces(TRUE);
foreach ($xml->channel[0]->item as $item) {
var_dump($item->children($ns['geo'])->lat);
var_dump($item->children($ns['geo'])->lon);
// do other stuff with $item here
}
Upvotes: 2