这是一个创建于 5303 天前的主题,其中的信息可能已经有所发展或是发生改变。
<?php
$sxe = simplexml_load_string('<books><book><title>Great American
Novel</title></book></books>');
if ($sxe === FALSE) {
echo 'Error while parsing the document';
exit;
}
$dom_sxe = dom_import_simplexml($sxe);
if (!$dom_sxe) {
echo 'Error while converting XML';
exit;
}
$dom = new DOMDocument('1.0');
$dom_sxe = $dom->importNode($dom_sxe, TRUE);
$dom_sxe = $dom->appendChild($dom_sxe);
echo $dom->saveXML('test2.xml');
?>
运行后出现:
Catchable fatal error: Argument 1 passed to DOMDocument::saveXML() must be an instance of DOMNode, string given in /opt/lampp/htdocs/app/xml_prac/DOM2SimpleXML.php on line 21
PHP Version 5.3.1
3 条回复 • 1970-01-01 08:00:00 +08:00
|
|
1
vayn 2010-04-29 10:59:31 +08:00
呃,找到原因了。
echo $dom->saveXML('test2.xml');
应该是
echo $dom->save('test2.xml');
怪不得会提示 DOMDocument::saveXML() must be an instance of DOMNode
囧
|
|
|
2
disinfeqt 2010-04-29 18:11:00 +08:00
应该发到自言自语区... 嗯
|
|
|
3
vayn 2010-04-29 22:27:17 +08:00
@ disinfeqt 本来等答案,结果变成自问自答,如果有 tag 选择我就把改成自言自语:D
|