2012-02-16 94 views
0

我不知道如何可以学得到的地方创建了xml位置并保存如下,保存XML文件

$document = new DOMDocument('1.0', 'utf-8'); 
    ....//write things to it 
    echo $document->saveXML(); 

我怎么知道它在哪里保存?作为流还是作为二进制文件?我可以获取或查看HD上的任何地方?我不知道为什么下面的红色信息表示我的帖子不符合我们的质量标准。我的帖子简短但可以理解。

回答

3

显然,saveXML()不是“拯救”高清文件,而只是返回的XML文档的字符串表示给你。为了将文档写入HD,您应该使用save($filename)

1

只是参考文档

http://www.php.net/manual/en/domdocument.save.php

int DOMDocument::save (string $filename [, int $options ]) 

filename 

    The path to the saved XML document. 
options 

    Additional Options. Currently only LIBXML_NOEMPTYTAG is supported. 

检查例子

<?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 'Wrote: ' . $doc->save("/tmp/test.xml") . ' bytes'; // Wrote: 72 bytes 

?>