2012-04-13 15:18
浏览 37

Zend_Feed访问项 - 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">

any idea how to access this with zend feed??

图片转代码服务由CSDN问答提供 功能建议

Iam尝试阅读“itunes RSS Feed”。 据我所知它是基于ATOM的。


  $ feed = $ this-&gt; getFeed(self:  :TOP300_PAYED); 
 foreach($ feed as $ item){
 echo $ item-&gt; name; 

但我需要 以下节点:

 &lt; im:image height =“53”&gt;  /9b/f2/mzl.wyuzxxzw.53x53-50.png

如何使用zend feed访问它?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongxian3852 2012-04-13 19:44

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

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

    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.

    打赏 评论
  • dongma6326 2012-04-15 07:36

    Thanks for the "Namespace" hint:

    Final solution:

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

相关推荐 更多相似问题