我正在为我们的网站实现一个用于Google产品搜索的feed生成器。由于Zend集成了一个提要写入器类,因此我决定使用Atom作为提要格式。
我已经做了一些工作,建立了一个基本的Atom提要,实际的产品数据将被注入其中,但我遇到了一个相当严重的问题。
Google希望提要文件是RSS或Atom的定制版本,并为Google Product Search使用的标签附加一个额外的命名空间。例如,<feed xmlns="http://www.w3.org/2005/Atom" xmlns:g="http://base.google.com/ns/1.0">。我一直在试图弄清楚如何附加额外的名称空间并在生成提要时使用它,但是Zend在这个问题上的文档充其量也是含糊其辞的,只提到了一些关于扩展的东西,没有深入任何细节。
我确实在文档中找到了将名称空间注册到zend_feed的说明,因此我尝试使用Zend_Feed::registerNamespace ('g', 'http://base.google.com/ns/1.0')附加所需的名称空间,但这似乎没有任何作用。
那么如何向zend提要添加额外的名称空间呢?它需要对zend_feed_writer_feed进行子类化吗?有没有什么插件系统可以做到这一点?或者我只需要以某种方式注册名称空间?
发布于 2011-10-28 19:55:53
从Zend_Feed_Atom扩展并添加:
class Gordons_Feed_Atom extends Zend_Feed_Atom {
protected function _mapFeedHeaders($array) {
$feed = parent::_mapFeedHeaders($array);
$feed->setAttribute('xmlns:g', '"http://base.google.com/ns/1.0');
return $feed;
}
}更新:
您必须覆盖_mapFeedEntries函数,然后在添加其他条目时添加条目:
$cond = $this->_element->createElement('g:condition');
$cond->appendChild($this->_element->createCDATASection($dataentry->gcondition));
$entry->appendChild($cond);你可以这样做:
protected function _mapFeedEntries(DOMElement $root, $array)
{
parent::_mapFeedEntries($root, $array);
foreach($array as $dataentry) {
//Add you're custom ones
$cond = $this->_element->createElement('g:condition');
$cond->appendChild($this->_element->createCDATASection($dataentry->gcondition));
$entry->appendChild($cond);
}
}该函数将确保您获得标准版本,然后您将成为自定义版本。
发布于 2012-04-23 19:23:18
Google Merchant Feed XML Atom1.0
我已经解决了我的Zend框架Google产品的问题。我的想法是覆盖主类,但我发现了一个更好的解决方案,我已经在我的项目中使用。
首先你需要一个Zend项目:P然后你需要创建一个新的Feed扩展,在你的/library/MyProject文件夹中创建一些文件夹,如下所示:
library/Myproject/Feed/
└── Writer
└── Extension
└── Google
├── Entry.php
├── Feed.php
└── Renderer
├── Entry.php
└── Feed.php然后你必须创建你自己的扩展。我已经在我自己的http://code.google.com/p/shineisp/source/browse/#svn%2Ftrunk%2Flibrary%2FShineisp%2FFeed%2FWriter%2FExtension%2FGoogle%253Fstate%253Dclosed项目中创建了自己的扩展Google
你可以随意使用我的代码!
.
.
.
.
<entry>
<title><![CDATA[Hosting Base]]></title>
<summary><![CDATA[this is the summary.]]></summary>
<updated>2012-04-23T13:09:55+02:00</updated>
<link rel="alternate" type="text/html" href="http://www.mysite.com/hosting.html"/>
<g:id>hosting-base</g:id>
<g:availability/>
<g:google_product_category/>
<g:image_link>http://www.mysite.com/media/products/854_web-hosting-base.gif</g:image_link>
<g:price>10.89</g:price>
<g:condition>new</g:condition>
</entry>
.
.
.
.https://stackoverflow.com/questions/7901316
复制相似问题