<?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 "Saving all the document:\n";
echo $doc->saveXML() . "\n";echo "Saving only the title part:\n";
echo $doc->saveXML($title);?>echo 出来只显示
Saving all the document: Saving only the title part:
xml的内容无法显示出来!
// 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);?>echo 出来只显示
Saving all the document: Saving only the title part:
xml的内容无法显示出来!
<?xml version="1.0"?>
<book>
<title>This is the title</title>
</book>Saving only the title part:
<title>This is the title</title>不知你期望的是什么
Saving all the document:
<?xml version="1.0"?>
<book>
<title>This is the title</title>
</book>
Saving only the title part:
<title>This is the title</title>
echo "Saving all the document:\n";
$a= $doc->saveXML() ;
echo $a. "\n";echo "Saving only the title part:\n";
$b= $doc->saveXML($title);
echo $b;
1、整个程序只有一次输出 echo $doc->saveXML();
2、必要时(视浏览器而定)需加类型声明的头 header("content-type:text/xml");