【www.gdgbn.com--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 "retrieving all the document: ";
echo $doc->savexml() . " ";

echo "retrieving only the title part: ";
echo $doc->savexml($title);

本文来源:http://www.gdgbn.com/jiaocheng/25392/