Reputation: 5240
I'm trying to parse a RSS based on simplePie and and the RSS which I want to parse is based on RDF.
and has some particular fields such as : "creator" / "identifier" / etc...
I read the simplePie document according how to get specific field from an rss and write the following code (mostlythe same as simplePie example):
the simplePie document link :
http://simplepie.org/wiki/reference/simplepie_item/get_item_tags
$feed = new SimplePie();
$feed->set_feed_url('http://www.nature.com/nchem/current_issue/rss');
$feed->enable_cache(false);
$success = $feed->init();
//$feed->handle_content_type('text/plain');
if ($success)
{
if ($item = $feed->get_item(0))
{
// This is probably a bad example because we already support <media:content> natively, but it shows you how to parse through the nodes.
$media_group = $item->get_item_tags('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'rdf');
$media_content = $media_group[0]['child']['http://www.w3.org/1999/02/22-rdf-syntax-ns#']['content'];
// $file = $media_content[0]['attribs']['']['url'];
// echo $file;
}
else
{
echo 'Error: Could not get first item';
}
}
else
{
echo $feed->error();
}
the media_group and media_content(of course) are always returning NULL
how can I get specific field from RSS?
Upvotes: 1
Views: 401
Reputation: 577
Non-standard feeds can give SimplePie and me headaches. You can get the raw XML from SimplePie and then use something else to parse/manipulate it. I've done that in some cases using SimpleHTMLDom...
Upvotes: 1