1

我希望有一个关于 Zend_Feed 的非常简单的问题,但由于某种原因,我无法弄清楚如何使用 Zend_Feed_Atom。

我正在尝试使用谷歌购物原子提要,如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<feed gd:kind="shopping#products" gd:etag="&quot;DGasYngxPSnbk2d57I7XFo1iC6s/xunARm6Ubdaw8jBCuFbVG_I6sSE&quot;" xmlns="http://www.w3.org/2005/Atom" xmlns:gd="http://schemas.google.com/g/2005" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:s="http://www.google.com/shopping/api/schemas/2010">
 <id>tag:google.com,2010:shopping/products</id>
 <updated>2012-02-05T15:35:48.784Z</updated>
 <title>Shopping Products</title>
 <generator version="v1" uri="https://www.googleapis.com/shopping/search/">Search API for Shopping</generator>
 <link rel="alternate" type="text/html" href="https://www.googleapis.com/shopping/search/"/>
 <link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="https://www.googleapis.com/shopping/search/v1/public/products?alt=atom"/>
 <link rel="self" type="application/atom+xml" href="https://www.googleapis.com/shopping/search/v1/public/products?country=GB&amp;q=digital+camera&amp;alt=atom&amp;startIndex=1&amp;maxResults=25"/>
 <link rel="next" type="application/atom+xml" href="https://www.googleapis.com/shopping/search/v1/public/products?country=GB&amp;q=digital+camera&amp;alt=atom&amp;startIndex=26&amp;maxResults=25"/>
 <link rel="previous" type="application/atom+xml"/>
 <openSearch:totalResults>2035890</openSearch:totalResults>
 <openSearch:startIndex>1</openSearch:startIndex>
 <openSearch:itemsPerPage>25</openSearch:itemsPerPage>
 <entry gd:kind="shopping#product">
  <id>tag:google.com,2010:shopping/products/5735617/15353500247539618129</id>
  <author>
   <name>Amazon.co.uk</name>
  </author>
  <published>2011-04-16T07:12:22.000Z</published>
  <updated>2012-02-05T02:40:54.000Z</updated>
  <title>Fujifilm FinePix S4000 Digital Camera - (14MP, 30x Optical Zoom) 3-inch LCD</title>
  <content type="text">The FinePix S4000 is a new bridge camera from Fujifilm thats truly geared up for a creative challenge. Complete with a 14 megapixel high resolution sensor, a massive 30x Fujinon optical zoom, 3.0 LCD screen and 720p HD video capture (30 fps). Plus, with the flexibility of manual or automatic controls, this camera wont fail to impress. Features such as Scene Recognition Auto, Easy Web Upload, a HDMI port and the added bonus of an Electronic Viewfinder, will all help to enhance your photos. The S4000 is suited to photography enthusiasts who are looking to branch out and improve their photographic skills.</content>
  <link rel="alternate" type="text/html" href="http://www.amazon.co.uk/dp/B004G8Q60K/ref=asc_df_B004G8Q60K6433986?smid=A2QB1IPRWM40B4&amp;tag=googlecouk06-21&amp;linkCode=asn&amp;creative=22242&amp;creativeASIN=B004G8Q60K"/>
  <link rel="self" type="application/atom+xml" href="https://www.googleapis.com/shopping/search/v1/public/products/5735617/gid/15353500247539618129?alt=atom"/>
  <s:product>
   <s:googleId>15353500247539618129</s:googleId>
   <s:author>
    <s:name>Amazon.co.uk</s:name>
    <s:accountId>5735617</s:accountId>
   </s:author>
   <s:creationTime>2011-04-16T07:12:22.000Z</s:creationTime>
   <s:modificationTime>2012-02-05T02:40:54.000Z</s:modificationTime>
   <s:country>GB</s:country>
   <s:language>en</s:language>
   <s:title>Fujifilm FinePix S4000 Digital Camera - (14MP, 30x Optical Zoom) 3-inch LCD</s:title>
   <s:description>The FinePix S4000 is a new bridge camera from Fujifilm thats truly geared up for a creative challenge. Complete with a 14 megapixel high resolution sensor, a massive 30x Fujinon optical zoom, 3.0 LCD screen and 720p HD video capture (30 fps). Plus, with the flexibility of manual or automatic controls, this camera wont fail to impress. Features such as Scene Recognition Auto, Easy Web Upload, a HDMI port and the added bonus of an Electronic Viewfinder, will all help to enhance your photos. The S4000 is suited to photography enthusiasts who are looking to branch out and improve their photographic skills.</s:description>
   <s:link>http://www.amazon.co.uk/dp/B004G8Q60K/ref=asc_df_B004G8Q60K6433986?smid=A2QB1IPRWM40B4&amp;tag=googlecouk06-21&amp;linkCode=asn&amp;creative=22242&amp;creativeASIN=B004G8Q60K</s:link>
   <s:brand>Fuji</s:brand>
   <s:condition>new</s:condition>
   <s:gtin>04547410150742</s:gtin>
   <s:gtins>
    <s:gtin>04547410150742</s:gtin>
   </s:gtins>
   <s:inventories>
    <s:inventory channel="online" availability="inStock">
     <s:price shipping="0.0" currency="GBP">168.0</s:price>
    </s:inventory>
   </s:inventories>
   <s:images>
    <s:image link="http://ecx.images-amazon.com/images/I/51qJG-LhpcL.jpg"/>
   </s:images>
  </s:product>
 </entry>

当我使用 Zend_Feed_Atom 时,我无法访问我需要访问的名称空间s:product 。所以我试图扩展 Zend_Reader_Entry 以访问原子条目中的产品元素。但是我无法获得扩展注册。

我的 Zend_Reader_Entry 看起来像这样:

<?php

class My_Google_Shopping_Product_Entry extends Zend_Feed_Reader_Extension_EntryAbstract{

    public function getTitle(){

        if(isset($this->_data['title'])){
            return $this->_data['title'];
        }

        $title = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/s:title');

        if(!$title){
            $title = null;
        }

        $this->_data['title'] = $title;

        return $this->_data['title'];
    }

    public function getPrice(){

        if(isset($this->_data['price'])){
            return $this->_data['price'];
        }

        $price = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/s.price');

        if(!$price){
            $price = null;
        }

        $this->_data['price'] = $price;

        return $this->_data['price'];
    }

    public function getDescription(){

        if(isset($this->_data['description'])){
            return $this->_data['description'];
        }

        $description = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/s:description');

        if(!$description){
            $description = null;
        }

        $this->_data['description'] = $title;

        return $this->_data['description'];
    }


    protected function _registerNamespaces(){

        $this->_xpath->registerNamespaces('s', 'http://www.google.com/shopping/api/schemas/2010');
    }

}

?>

我正在尝试像这样加载它:

if(!Zend_Feed_Reader::isRegistered('Product')){
            Zend_Feed_Reader::addPrefixPath('/My/Google/Shopping','My_Google_Shopping');
        }

        Zend_Feed_Reader::registerExtension('Product');

        $feed = Zend_Feed_Reader::import($feedUrl);

知道为什么这不会加载,主要是如果我这样做是为了从原子提要中提取数据。

非常感谢,

授予

4

0 回答 0