在 PHP 5.2.9-2 和 PHP 5.2.17 中,importNode($node, false) 的行為不同。
第二個選項明確設為 false。在 PHP 5.2.9-2 中,importNode() 會匯入**沒有**屬性的元素。在 PHP 5.2.17 中,匯入的元素**包含**其屬性。
<?php
$xml="
<html>
<a href='yandex.com'>Yandex.com</a>
<a href='rik.dn.ua'>RiK.dn.ua</a>
</html>
";
$doc=new domDocument('1.0');
$doc->loadXML($xml);
$list=$doc->getElementsByTagName('a');
$doc1=new domDocument('1.0');
$doc1->formatOutput=true;
for($i=0; $i<$list->length; $i++) $doc1->appendChild($doc1->importNode($list->item($i), false));
$doc1->save('file.xml');
?>
file.xml PHP 5.2.9-2
<?xml version="1.0"?>
<a/>
<a/>
file.xml PHP 5.2.17
<?xml version="1.0"?>
<a href="yandex.com"/>
<a href="rik.dn.ua"/>