Problems with creating XML with DOMDocument in PHP

Posted by maralbjo on Stack Overflow See other posts from Stack Overflow or by maralbjo
Published on 2010-05-01T12:48:05Z Indexed on 2010/05/01 13:37 UTC
Read the original article Hit count: 288

Filed under:
|
|

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);

© Stack Overflow or respective owner

Related posts about php

Related posts about dom