<?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的内容无法显示出来!

解决方案 »

  1.   

    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>不知你期望的是什么
      

  2.   

    源文件:
    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>
      

  3.   

    怎么不能把这XML当成字符值给一个变量,然后echo出来呢?
      

  4.   

    这样?
    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;
      

  5.   

    输出xml文档?  头部加上: header("content-type:text/xml");  且把第二段输出注释掉。
      

  6.   

    如果需要在页面中显示,那么需要:
    1、整个程序只有一次输出 echo $doc->saveXML();
    2、必要时(视浏览器而定)需加类型声明的头 header("content-type:text/xml");