ZF-44: Import of rss feed (bug?) (TRAC#41 Johannes Orth)
Description
Hi,
while coding a FeedBuilder? I noticed a behaviour of ZendFeed?, which I consider as a bug:
$channel = new Zend_Feed_Rss('http://rss.example.com/channelName');
//modify...
echo $channel->saveXML();
The resulting xml does not include the root element.As Zend_Feed_Rss uses the tag as root item (Zend_Feed_Rss::wakeup), this should be reversed in the saveXML function. Here is a simple patch.
--- Rss.php 2006-05-09 15:49:37.738145112 +0200
+++ RssPatched.php 2006-05-09 16:01:23.601837520 +0200
@@ -53,6 +53,10 @@
/**
*/
protected $_defaultNamespace = 'rss';
+
+ /**
+ */
+ protected $_rssVersion;
/**
@@ -61,7 +65,10 @@
public function __wakeup()
{
parent::__wakeup();
-
+
+ // Store rss version attribute
+ $this->_rssVersion = $this->_element->documentElement->getAttribute('version');
+
// Find the base feed element and create an alias to it.
$this->_element = $this->_element->getElementsByTagName('channel')->item(0);
if (!$this->_element) {
@@ -72,6 +79,21 @@
// simplicity.
$this->_buildEntryCache();
}
+
+ /**
+ * Override Zend_Feed_Element to include root element
+ */
+ public function saveXML()
+ {
+ // Return a complete document including XML prologue.
+ $doc = new DOMDocument($this->_element->ownerDocument->version,
+ $this->_element->ownerDocument->actualEncoding);
+ $root = $doc->createElement('rss');
+ $root->setAttribute('version', $this->_rssVersion);
+ $root->appendChild($doc->importNode($this->_element, true));
+ $doc->appendChild($root);
+ return $doc->saveXML();
+ }
}
Comments
Posted by Darby Felton (darby) on 2006-06-20T11:58:18.000+0000
05/11/06 14:56:27: Modified by Johannes Orth projectphoenix@gmx.net
Oops, do not apply this patch. I think it breaks the serializing functions, I will have a deeper look at this.
Posted by Bill Karwin (bkarwin) on 2006-11-13T15:26:54.000+0000
Changing fix version to 0.6.0.
Posted by Matthew Turland (elazar) on 2008-02-03T09:40:39.000+0000
Johannes, can you please provide an actual code snippet using a specific feed that exposes this bug?
Posted by Simone Carletti (weppos) on 2008-02-05T15:03:31.000+0000
As of ZF 1.0.3 this bug no longer exists. saveXML() function apply by default an RSS 2.0 version to each imported feed using the following statement