日期:2014-05-16 浏览次数:20556 次
$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";
$xmlContent = $doc->saveXML();
var_dump($xmlContent);
Saving all the document:
string(72) "<?xml version="1.0"?>
<book>
<title>This is the title</title>
</book>
"