note 44735 added to function.dom-domdocument-savexml

From: Date: Sat, 14 Aug 2004 21:57:11 +0000
Subject: note 44735 added to function.dom-domdocument-savexml
Groups: php.notes 
Request: Send a blank email to php-notes+get-74649@lists.php.net to get a copy of this message
Output formatting It is possible to output the XML code with indents and line breaks, making it more human-readable. To activate formatting, set the property DOMDocument->formatOutput to true before calling DOMDocument->saveXML() or DOMDocument->save(). Example: <?php // create the document $doc = new DOMDocument(); // create the nodes $root = $doc->createElement("html"); $root = $doc->appendChild($root); $head = $doc->createElement("head"); $head = $root->appendChild($head); $title = $doc->createElement("title"); $title = $head->appendChild($title); $text = $doc->createTextNode("This is the title"); $text = $title->appendChild($text); // output the XML code without formatting print $doc->saveXML(); // output: // <html><head><title>This is the title</title></head></html> // activate formatting $doc->formatOutput = true; // output the XML code with formatting print $doc->saveXML(); // output: // <html> // <head> // <title>This is the title</title> // </head> // </html> ?> Note that this option does not apply to DOMDocument->saveHTML() or DOMDocument->saveHTMLFile(). It also does not seem to work on documents that were loaded from an XML file or string. A user reported that output formatting could be achieved by setting the property DOMDocument->preserveWhiteSpace to false before loading the data, but in my case, this did not make any difference (PHP 5.0.0). There is also a PEAR class that formats XML output without the use of DOM: http://pear.php.net/package/XML_Beautifier Marcel Kiel ---- Manual Page -- http://www.php.net/manual/en/function.dom-domdocument-savexml.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+44735 Delete -- http://master.php.net/manage/user-notes.php?action=delete+44735&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+44735&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#74649) next »