Friday, 10 June 2016

XML : SimpleXML not printing XML declaration

I'm created a dynamically generated XML document with SimpleXML in PHP7.

The issue I'm facing is that the XML is not being produced with the XML declaration - and I've tried various methods unsuccessfully of doing it - currently I have the following:

  $xml = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><urlset />');    //more code    header('Content-Type: application/xml');    echo($xml->asXML());    

The XML declaration should be this, at the top of the document:

  <?xml version="1.0" encoding="utf-8"?>    

I've also tried sketchy things like printing the declaration before the XML - to no avail.

If you need more info please let me know!

Related question = XML Declaration Tag using SimpleXML

No comments:

Post a Comment