向Zend_Feed_Writer_Feed添加名称空间 [英] Adding a namespace to a Zend_Feed_Writer_Feed

查看:108
本文介绍了向Zend_Feed_Writer_Feed添加名称空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力为我们的网站实现供Google产品搜索使用的供稿生成器. Zend合并了feed编写器类,因此我决定将Atom用作feed格式.

I'm working on implementing a feed generator for use with Google Product Search for our sites. As Zend incorporates a feed writer class, I decided to go with Atom for the feed format.

我已经完成了一些工作,构建了将实际产品数据注入其中的准原子Atom提要,但是我遇到了一个相当严重的问题.

I've done some work building up a bare-bones Atom feed into which the real product data will be injected, but I've hit a fairly serious snag.

Google希望供稿文件是RSS或Atom的自定义版本,并为Google购物搜索所使用的标签附加一个附加的名称空间.例如,<feed xmlns="http://www.w3.org/2005/Atom" xmlns:g="http://base.google.com/ns/1.0">.我一直在尝试找出如何附加额外的名称空间并在生成提要中使用它,但是Zend的文档充其量是含糊的,在不涉及任何细节的情况下提及扩展.

Google want a feed file to be a customised version of either RSS or Atom, with an additional namespace attached for the tags Google Product Search uses. For example, <feed xmlns="http://www.w3.org/2005/Atom" xmlns:g="http://base.google.com/ns/1.0">. I've been trying to figure out how to attach the additional namespace and use it in generating the feed, but Zend's documentation on the matter is vague at best, mentioning something about extensions without going into any great detail.

在将名称空间注册到zend_feed的文档中,我也确实提到过,因此我尝试Zend_Feed::registerNamespace ('g', 'http://base.google.com/ns/1.0')附加所需的名称空间,但这似乎无济于事.

I did also find mention in the documentation of registering namespaces to zend_feed, so I tried Zend_Feed::registerNamespace ('g', 'http://base.google.com/ns/1.0') to attach the needed namespace, but this didn't appear to do anything.

那么如何将其他名称空间添加到zend feed?是否需要将zend_feed_writer_feed子类化?是否有某种允许这样做的插件系统?还是只需要以某种方式注册名称空间?

So how do I add additional namespaces to a zend feed? Does it require subclassing the zend_feed_writer_feed? is there some kind of plugin system that allows this? Or do I just need to register the namespace somehow?

推荐答案

从Zend_Feed_Atom扩展并添加:

Extend from Zend_Feed_Atom and add:

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函数,然后在添加其他条目时添加条目:

You will have to override the _mapFeedEntries function and then add the entries as the others are added:

    $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);
    } 
}

该功能将确保您获得标准的,然后成为自定义的.

That function would ensure you get the standard ones and then you're custom ones.

这篇关于向Zend_Feed_Writer_Feed添加名称空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆