I'm having some problems with parsing RSS feeds with Zend_Feed_Reader, specifically when a RSS namespace is being used.
The feed I'm trying to parse is the BBC News feed (http://feeds.bbci.co.uk/news/rss.xml) which includes the following:
<item>
<media:thumbnail width="66" height="49" url="http://news.bbcimg.co.uk/media/images/55800000/jpg/_55800088_013076641-1.jpg"/>
<media:thumbnail width="144" height="81" url="http://news.bbcimg.co.uk/media/images/55807000/jpg/_55807247_013074606-1.jpg"/>
</item>
The code I'm using to parse the other items in <item>
is as such:
$feed = Zend_Feed_Reader::import('http://feeds.bbci.co.uk/news/rss.xml');
foreach($feed as $item)
{
echo $item->getTitle();
echo $item->getDescription();
// etc
}
However, using $item->getMedia()
, $item->getMedia('thumbnail')
, $item->{'media:thumbnail'}
or $item->{'media:thumbnail'}()
doesn't work.
I also tried writing my own extension (using this as a guide):
class Zend_Feed_Reader_Extension_Media_Entry extends Zend_Feed_Reader_Extension_EntryAbstract
{
public function getThumbnail()
{
if(isset($this->_data['thumbnail']))
return $this->_data['thumbnail'];
$thumbnail = $this->_xpath->evaluate(
'string(' . $this->getXpathPrefix() . '/media:thumbnail)'
);
if(!$thumbnail)
$thumbnail = null;
$this->_data['thumbnail'] = $thumbnail;
return $this->_data['thumbnail'];
}
protected function _registerNamespaces()
{
$this->_xpath->registerNamespace('media', 'http://search.yahoo.com/mrss');
}
}
And then doing all the appropriate extension registering (Zend_Feed_Reader::registerExtension('media');
) returns a null when running $item->getThumbnail()
.
Does anyone have any ideas?