Zend_Feed access item - ATOM

176 Views Asked by At

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??

2

There are 2 best solutions below

0
On BEST ANSWER

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.

1
On

Thanks for the "Namespace" hint:

Final solution:

        $item->registerXPathNamespace('im', 'image');
        $image = (string) $item->image[0]; // first image "52"