I’m trying to an xml response to object via SimpleXMLElement. But an element of XML disappears with this operation. Take a look at XML and SimpleXMLElement clearly:
<item><pubDate>Wed, 28 Dec 2011 13:04:30 GMT</pubDate><title>M 1.2, Nevada</title><description>December 28, 2011 13:04:30 GMT</description><link>http://earthquake.usgs.gov/earthquakes/recenteqsus/Quakes/nn00361989.php</link><geo:lat>37.4048</geo:lat><geo:long>-117.0953</geo:long><dc:subject>1</dc:subject><dc:subject>pasthour</dc:subject><dc:subject>7.00 km</dc:subject><guid isPermaLink="false">nn00361989</guid></item>
And here is the SimpleXMLElement return:
[item] => SimpleXMLElement Object
(
[pubDate] => Wed, 28 Dec 2011 13:04:30 GMT
[title] => M 1.2, Nevada
[description] => December 28, 2011 13:04:30 GMT
[link] => http://earthquake.usgs.gov/earthquakes/recenteqsus/Quakes/nn00361989.php
[guid] => nn00361989
)
As you see there’s not geo lat and long info here. I am trying this code for creating SimpleXMLObject:
$doc = new SimpleXMLElement($response)
Must i use an parameter with this?
Your geodata is namespaced in the XML, so you need to tell simplexml that there is also data namespaced with ‘geo’
Note that your xml fragment is badly formed because there’s no namespace declarations