note 113191 modified in domdocument.importnode by peehaa
| From: | peehaa@php.net | Date: | Wed, 11 Sep 2013 07:52:04 +0000 |
| Subject: | note 113191 modified in domdocument.importnode by peehaa | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-196219@lists.php.net to get a copy of this message | ||
The behavior of importNode($node, false) is different in PHP 5.2.9-2 and PHP 5.2.17.
The second option is explicitly set to false. In PHP 5.2.9-2 importNode() imports the elements
WITHOUT attributes. In PHP 5.2.17 the elements imported ALONG with their attributes.
<?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"/>
--was--
Ðоведение ÑÑнкÑии importNode($node, false)
ÑазлиÑно в PHP 5.2.9-2 и в PHP 5.2.17.
ÐÑоÑой паÑамеÑÑ Ñвно
ÑÑÑанавливаем ÑавнÑм false. Ð PHP
5.2.9-2 importNode() импоÑÑиÑÑÐµÑ ÑлеменÑÑ
ÐÐРаÑÑибÑÑов. Ð PHP 5.2.17 ÑлеменÑÑ
импоÑÑиÑÑÑÑÑÑ ÐÐÐСТРÑо
Ñвоими аÑÑибÑÑами.
The behavior of importNode($node, false) is different in PHP 5.2.9-2 and PHP 5.2.17.
The second option is explicitly set to false. In PHP 5.2.9-2 importNode() imports the elements
WITHOUT attributes. In PHP 5.2.17 the elements imported ALONG with their attributes.
<?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"/>
http://php.net/manual/en/domdocument.importnode.php