Jump to content


Photo

SimpleXml + Media RSS *SOLVED*


  • Please log in to reply
3 replies to this topic

#1 ddeile

ddeile
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 24 September 2006 - 07:21 PM

Hello,

I'm new here, love the site.  Anyway, I've been trying to use the SimpleXml module to parse media rss files.  I'm creating a generic rss parser to pull the <media:thumbnail> out of rss feeds.  I've spent the last few days doing this numerous way, but have been unable to return data.

Here are a few of my recent attempts:

Note: I'm using an rss feed from Flickr in these examples.

$entries = simplexml_load_file('http://api.flickr.com/services/feeds/photos_public.gne?tags=tokyo&format=rss_200');

foreach($entries->children('http://search.yahoo.com/mrss') as $item)
{
  echo $item->thumbnail->attributes();
}


and:

$entries = simplexml_load_file('http://api.flickr.com/services/feeds/photos_public.gne?tags=tokyo&format=rss_200');
  
foreach($entries->channel->item as $feeditem)
{
	$thumbnail = $feeditem->children('http://search.yahoo.com/mrss')->thumbnail->attributes();
}


and:

$entries = simplexml_load_file('http://api.flickr.com/services/feeds/photos_public.gne?tags=tokyo&format=rss_200');
  
foreach($entries->channel->item as $feeditem)
{	
	foreach ($feeditem->children('http://search.yahoo.com/mrss') as $entry) 
        {
             echo $entry->thumbnail->attributes();
        }
	
}

Can anyone offer any help or suggestions?

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 24 September 2006 - 07:56 PM

try
<?php
$entries = simplexml_load_file('http://api.flickr.com/services/feeds/photos_public.gne?tags=tokyo&format=rss_200');
$data = $entries->xpath ('channel/item/media:thumbnail');
foreach ($data as $item) {
    echo $item['url'].'<br>';
}
    
?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 ddeile

ddeile
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 24 September 2006 - 07:57 PM

SOLVED!

I forgot to echo out my $thumnail variable in my second example.  Here is the code:

$entries = simplexml_load_file('http://api.flickr.com/services/feeds/photos_public.gne?tags=tokyo&format=rss_200');
  
foreach($entries->channel->item as $feeditem)
{
	$thumbnail = $feeditem->children('http://search.yahoo.com/mrss')->thumbnail->attributes();
	echo $thumbnail[0];
}


#4 ddeile

ddeile
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 24 September 2006 - 07:59 PM

Thanks Barand.  That works as well. ;D




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users