Therefore I post here a save function.
function simpledom_save_file(&$simpleDom, $filepath = null) { $dom = new DOMDocument('1.0'); $dom->preserveWhiteSpace = false; $dom->formatOutput = true; $dom->loadXML ($simpleDom->asXML()); $result = $dom->saveXML ();
if (isset($filepath)) { return (bool) file_put_contents($filepath, $result); }
return $result; }
Comment #1
Posted on Jul 19, 2011 by Swift HippoActually, this method already exists. SimpleXML offers the asXML() method, to which you can pass a filepath if you want the output to be saved. SimpleDOM offers the asPrettyXML() method, which does an equivalent job except that the output is indented with libxml's "formatOuput" option as in your example. Enjoy!
$node = new SimpleDOM('<root><child1><grandchild1 /></child1><child2 /><child3 /></root>');
// if you want to see the result
echo $node->asPrettyXML();
// if you want to save the result
$node->asPrettyXML('/tmp/result.xml');
Comment #2
Posted on Jul 19, 2011 by Swift Hippo(No comment was entered for this change.)
Comment #3
Posted on Jul 21, 2011 by Happy MonkeyYes, I know. I know also that you need the XSLT processor up and running. This is not standard in my php config from xampp.
Bye, Karel.
Status: Invalid
Labels:
Type-Defect
Priority-Medium