I've got a SimpleXMLElement for which I read in a XML file using curl. Trying to get the values out of it I seem to need to use a nested foreach, but in a similar situation I was able to do this in one go. Now I'm really curious why this isn't working:
Its the delicious RSS feed;
SimpleXMLElement Object
(
[title] => Delicious/chrisvdberge
[link] => http://www.delicious.com/chrisvdberge
[description] => bookmarks posted by chrisvdberge
[item] => Array
(
[0] => SimpleXMLElement Object
(
[title] => Diagrammr
[pubDate] => Thu, 06 May 2010 12:40:07 +0000
[guid] => http://www.delicious.com/url/2fc2ed0e870ec9d001b645dfaed0e771#chrisvdberge
[link] => http://www.diagrammr.com/
[comments] => http://www.delicious.com/url/2fc2ed0e870ec9d001b645dfaed0e771
[source] => chrisvdberge's bookmarks
[category] => Array
(
[0] => tagthis
[1] => visualization
[2] => diagrams
)
)
[1] => SimpleXMLElement Object
(
[title] => Ignite Toronto 2: Ryan Coleman - Designing for visual efficiency on Vimeo
[pubDate] => Mon, 18 Jan 2010 08:05:06 +0000
[guid] => http://www.delicious.com/url/9a0de307f3f37baaa25ad20b4dbc4537#chrisvdberge
[link] => http://vimeo.com/8317770
[comments] => http://www.delicious.com/url/9a0de307f3f37baaa25ad20b4dbc4537
[source] => chrisvdberge's bookmarks
[category] => Array
(
[0] => tagthis
[1] => vizthink
)
)
etc.
I can access all the links by using a nested foreach:
foreach ($delicious_res as $item) {
foreach ($item->item as $entry){
echo $entry->link."<br />";
}
}
But I don't understand why I cant use this (which I can in another situation)
foreach ($delicious_res->item as $item) {
echo $entry->link."<br />";
}
I really like to understand why in order to get a better understanding of SimpleXML in general ;)