Page 1 of 1

Zend_Feed_RSS Categories

Posted: Thu May 13, 2010 4:48 am
by onion2k
I'm reading an RSS feed that contains elements like:

Code: Select all

<item>
<title>This is the title</title>
<link>http://link.com/</link>
<description>Description blah blah blah</description>
<category>Gardening</category>
<category>Plants</category>
<category>Flowers</category>
</item>
How do I access those categories? I've sort of figured it out using this:

Code: Select all

    $channel = new Zend_Feed_Rss("http://domain.com/rss");

    foreach ($channel as $item) {
        echo $item->title() . "<br />";
        echo $item->description() . "<br />";
        $categories = $item->category();
        foreach ($categories as $c) {
            echo $c->nodeValue;
        }
        echo "<br /><br />";
    }
That can't be right though, surely? That's completely abusing the DOM object nodes and accessing things I shouldn't be accessing publicly. I've looked through the documentation for Zend_Feed_Reader but the getCategories() method didn't seem to work for the RSS feed I'm consuming.

Re: Zend_Feed_RSS Categories

Posted: Thu May 13, 2010 1:57 pm
by Christopher
Have you dumped the feed object to see what it actually contains. It may only have the last category entry.