aligning the xml document
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>&开发者_如何学Golt;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(); }
Use newlines and tabs with "\n" and "\t" respectively, in double quotes in your PHP code.
If you want to display it in easily readable form, http://gdatatips.blogspot.com/2008/11/xml-php-pretty-printer.html
精彩评论