mardi 4 août 2015

Line breaks in PHP xmlwriter document

I've got an XML feed I've created using XMLWriter. It works flawlessly in dev on a PHP 5.6 vagrant box. On the live server, running PHP 5.4 the feed fails to render with a message:

This page contains the following errors:

error on line 3 at column 6: XML declaration allowed only at the start of the document

If you view source it looks like this:

source

Somehow there are a couple lines being added into the XML document. The only difference between the servers is the PHP version (as far as I know).

Here's the first few lines of the XMLWriter code:

$xml = new XMLWriter();
$xml->openURI('php://output');
$xml->startDocument("1.0");
$xml->setIndent(true);
$xml->startElement("propertyList");
$xml->writeAttribute('date', date('Y-m-d-H:i:s'));

Any ideas how to get around this?

Aucun commentaire:

Enregistrer un commentaire