Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 407
user398341 Avatar asked Apr 18 '11 16:04

user398341


1 Answers

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

like image 172
hrvoj3e Avatar answered Sep 18 '22 03:09

hrvoj3e