Search code examples
phpzend-frameworkzend-feed

Zend_Feed access item - ATOM


Iam trying to read the "itunes RSS Feed". As far as i know it is ATOM based.

Works fine:

    $feed = $this->getFeed(self::TOP300_PAYED);

    foreach ($feed as $item) {
        echo $item->name;
    }

But i need the following node:

<im:image height="53">
http://a3.mzstatic.com/us/r1000/116/Purple/61/9b/f2/mzl.wyuzxxzw.53x53-50.png
</im:image>

any idea how to access this with zend feed??


Solution

  • Like any other ATOM feed, you can iterate over it like this:

        $feed = new Zend_Feed_Atom("example.com");
        foreach ($feed as $entry) {
            $xml = $entry->saveXml();
            $xmlObj = simplexml_load_string($xml);
    
            $xmlObj->registerXPathNamespace('im', "example.com");
            $result = $xmlObj->xpath('//im:image');
    
            foreach ($result as $image) {
              echo $image . "\n";
            }
        }
    

    Note the use of registerXPathNamespace() here, it seems that iTunes uses namespace in their feed, this is the reason why you need to register it first.

    Try this and let me know if it works.