XML generation error.
- by Janis Peisenieks
I'm trying to generate an XML output with Zend_Framework, but this nasty thing keeps popping up:
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"?>
^
As far as I know there are no white-spaces in any of my include files, and even if there were, I think that the ob_clean() function should have taken care of it. Here is my code:
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);
}
Any help or suggestions?