views:

159

answers:

2

Whenever I output an xml file, I always get 9 blank lines of whitespace at the top, anyone know what the problem is? I also get a timestamp at the end which I don't want:

<!-- 0.35s -->

Here's the error:

XML Parsing Error: XML or text declaration not at start of entity
Location: http://example.com/controller/get
Line Number 9, Column 1:<?xml version="1.0" encoding="UTF-8" ?>

I put $this->RequestHandler->setContent('xml','text/xml'); in my controller's beforeFilter(), and the view looks like this:

<?php echo $xml->serialize($data); ?>

while the layout looks like this:

<?php
    header("content-type: text/xml");
    echo $this->Xml->header();
    echo $content_for_layout;
?>

Any ideas? Thanks.

+1  A: 

The timestamp is appended in app/webroot/index.php, so you can remove it by editing this file (you find the respective code at the end of the file).

dhofstet
Thanks, this got rid of the timestamp, but the 9 newlines still persist...
Jasie
+1  A: 

You can also set Configure::write('debug', 0); into controllers beforeFilter() or any other method/serviceCall before rendering to get rid of the timestamp.

kaupov
You can also put Configure::write('debug', 0) in your layout.
KahWee Teng