<?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
$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