i’m inserting the data into an xml file using php domdocument. however when i open the xml file, the data is displayed in a single line:
<?xml version="1.0"?>
<root><activity>swimming</activity><activity>jogging</activity></root>
how do i align it programmatically like this?
<?xml version="1.0"?>
<root>
<activity>swimming</activity>
<activity>jogging</activity>
</root>
You can use this function
function pretty_xml($string) { $xml = DOMDocument::loadXML($string); $xml->formatOutput = true; return $xml->saveXML(); }