opHasNoName
opHasNoName

Reputation: 20736

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

Upvotes: 2

Views: 163

Answers (2)

opHasNoName
opHasNoName

Reputation: 20736

Thanks for the "Namespace" hint:

Final solution:

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

Upvotes: 1

Liyali
Liyali

Reputation: 5693

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.

Upvotes: 3

Related Questions