Save the internal XML tree back into a file in PHP
Description
The following code shows how to save the internal XML tree back into a file.
Example
//from ww w .ja v a 2 s . c om
<?php
$doc = new DOMDocument('1.0');
// we want a nice output
$doc->formatOutput = true;
$root = $doc->createElement('book');
$root = $doc->appendChild($root);
$title = $doc->createElement('title');
$title = $root->appendChild($title);
$text = $doc->createTextNode('This is the title');
$text = $title->appendChild($text);
echo 'Wrote: ' . $doc->save("test.xml") . ' bytes';
?>
The code above generates the following result.