我試圖生成Zend_Framework一個XML輸出,但這個討厭的事情不斷彈出:XML生成錯誤
XML Parsing Error: XML or text declaration not at start of entity
Location: http://cart/index/kurpirkt
Line Number 2, Column 1:<?xml version="1.0" encoding="utf-8"?>
^
據我所知沒有白空間在我的任何包含文件,即使有,我認爲ob_clean()
函數應該照顧它。這裏是我的代碼:
public function kurpirktAction()
{
ob_clean();
// XML-related routine
$xml = new DOMDocument('1.0', 'utf-8');
$xml->appendChild($xml->createElement('foo', 'bar'));
$output = $xml->saveXML();
// Both layout and view renderer should be disabled
Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->setNoRender(true);
Zend_Layout::getMvcInstance()->disableLayout();
// Setting up headers and body
$this->_response->setHeader('Content-Type', 'text/xml; charset=utf-8')
->setBody($output);
}
任何幫助或建議?
就注意到,創建文檔1.0版本,但都出現了我們在錯誤的版本1.2。 – 2011-01-05 21:35:13
我的不好,當我發佈錯誤消息時,正在搞亂。我更新了它! – 2011-01-05 21:38:32