Yii扩展XML分析错误:找不到元素


Yii extension XML Parsing Error: no element found

我正在使用这个RSS扩展,并遵循了文档中的示例。

在我的视图

 Yii::import('ext.feed.*');
// RSS 2.0 is the default type
$feed = new EFeed();
$feed->title= 'Testing RSS 2.0 EFeed class';
$feed->description = 'This is test of creating a RSS 2.0 Feed';
$feed->setImage('Testing RSS 2.0 EFeed class','http://www.ramirezcobos.com/rss',
'http://www.yiiframework.com/forum/uploads/profile/photo-7106.jpg');
$feed->addChannelTag('language', 'en-us');
$feed->addChannelTag('pubDate', date(DATE_RSS, time()));
$feed->addChannelTag('link', 'http://www.ramirezcobos.com/rss' );
// * self reference
$feed->addChannelTag('atom:link','http://www.ramirezcobos.com/rss/');
$item = $feed->createNewItem();
$item->title = "first Feed";
$item->link = "http://www.yahoo.com";
$item->date = time();
$item->description = 'This is test of adding CDATA Encoded description <b>EFeed Extension</b>';
// this is just a test!!
$item->setEncloser('http://www.tester.com', '1283629', 'audio/mpeg');
$item->addTag('author', 'thisisnot@myemail.com (Antonio Ramirez)');
$item->addTag('guid', 'http://www.ramirezcobos.com/',array('isPermaLink'=>'true'));
$feed->addItem($item);
$feed->generateFeed();
Yii::app()->end();

在我的控制器中

public function actionFeed()
{
    $this->renderPartial('feed');
}

在Firefox中我得到这个错误

XML Parsing Error: XML or text declaration not at start of entity
Location: http://localhost/dev/frontend/www/abc/bla/feed/
Line Number 1, Column 2: <?xml version="1.0" encoding="UTF-8"?>
-^

和铬

This page contains the following errors:
error on line 1 at column 6: XML declaration allowed only at the start of the document
Below is a rendering of the page up to the first error.

在扩展中有这个功能

public function generateFeed(){
        header("Content-type: text/xml");
        $this->renderHead();
        $this->renderChannels();
        $this->renderItems();
        $this->renderBottom();
    }

当我注释掉header("Content-type: text/xml");时,没有错误,但页面显示为html,并且全部显示在一行中。但当您查看源代码时,标记都已就位。

前2行看起来像这个

 <?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">

知道我做错了什么吗?

更改

<xml version="1.0" encoding="utf-8">

<?xml version="1.0" encoding="UTF-8"?>

参见标签后的问号(?)

更新:

您的xml应该是字符串或像一样位于单引号内

<?php header("Content-type: application/xml"); 
echo  
'<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>RSS2 Feed</title>
<link>http://www.url.com/</link>
</channel>
</rss>';
?>