Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple XML - Dealing With Colons In Nodes

Tags:

php

xml

simplexml

I'm trying to read an RSS feed from Flickr but it has some nodes which are not readable by Simple XML (media:thumbnail, flickr:profile, and so on).

How do I get round this? My head hurts when I look at the documentation for the DOM. So I'd like to avoid it as I don't want to learn.

I'm trying to get the thumbnail by the way.

like image 566
Ben Shelock Avatar asked Jul 27 '09 01:07

Ben Shelock


1 Answers

The solution is explained in this nice article. You need the children() method for accessing XML elements which contain a namespace. This code snippet is quoted from the article:

$feed = simplexml_load_file('http://www.sitepoint.com/recent.rdf'); 
foreach ($feed->item as $item) { 
    $ns_dc = $item->children('http://purl.org/dc/elements/1.1/'); 
    echo $ns_dc->date; 
}
like image 114
vog Avatar answered Oct 14 '22 12:10

vog