Problems with creating XML with DOMDocument in PHP
- by maralbjo
The below code is fetched from php.net (http://docs.php.net/manual/en/domdocument.savexml.php). My problem is - it doesn't work. My only output from this is: "Saving all the document: Saving only the title part:". What am I missing here?
$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 "Saving all the document:\n";
echo $doc-saveXML() . "\n";
echo "Saving only the title part:\n";
echo $doc-saveXML($title);