PHP simpleXML how to save the file in a formatted way?

You could use the DOMDocument class to reformat your code:

$dom = new DOMDocument('1.0');
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->loadXML($simpleXml->asXML());
echo $dom->saveXML();

Leave a Comment