Alex Rivera | Logout

PHP DomDocument output without <?xml version="1.0" encoding="UTF-8"?>

Asked 2011-04-18T16:42:44.097
37

is there an option with DomDocument to remove the first line:

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

The class instantiation automatically adds it to the output, but is it possible to get rid of it?

Edit
Report

1 Answer

37

I think using DOMDocument is a universal solution for valid XML files:

If you have XML already loaded in a variable:

$t_xml = new DOMDocument();
$t_xml->loadXML($xml_as_string);
$xml_out = $t_xml->saveXML($t_xml->documentElement);

For XML file from disk:

$t_xml = new DOMDocument();
$t_xml->load($file_path_to_xml);
$xml_out = $t_xml->saveXML($t_xml->documentElement);

This comment helped: http://www.php.net/manual/en/domdocument.savexml.php#88525

answered 2013-06-28T10:19:08.730

Your Answer