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.
The 9 blank lines are probably because you have lines with whitespace at the end of some of the php files in your project. This has caught me out several times in CakePHP.
For a simple way to remove blank lines at the end of all your php files, see this post: Find all files with Blank or WS at BOF or EOF