note 83178 added to class.domnodelist
| From: | drichter at muvicom dot de | Date: | Wed, 14 May 2008 11:56:18 +0000 |
| Subject: | note 83178 added to class.domnodelist | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-139370@lists.php.net to get a copy of this message | ||
I have done some testing and have found 2 results:
(My System: Win XP with PHP 5.2.1)
1) Iteration with foreach does function correctly as "james dot j dot hackett at gmail dot
com" writes, _if_ you only do readonly stuff with foreach or minor writings of some attributes.
2) foreach does not function, if you are doing some DOM-Operations while iterating. In my situation
it was adding the iterated $node as an child to an new node:
$newNode = $dom->createElement('newNode') ;
foreach ($nodeList as $node) {
echo $node->nodeValue ;
$newNode->appendChild($node) ;
}
This only gives you the first element ...
I'm interpreting it as an confusing but correct behavior because of the changes within the
$dom-object while appending the node at an additional place ...
So, if you want to do something like 2) use for, length and item() :)
----
Server IP: 217.160.72.57
Probable Submitter: 84.189.145.13
----
Manual Page -- http://www.php.net/manual/en/class.domnodelist.php
Edit -- https://master.php.net/note/edit/83178
Del: integrated -- https://master.php.net/note/delete/83178/integrated
Del: useless -- https://master.php.net/note/delete/83178/useless
Del: bad code -- https://master.php.net/note/delete/83178/bad+code
Del: spam -- https://master.php.net/note/delete/83178/spam
Del: non-english -- https://master.php.net/note/delete/83178/non-english
Del: in docs -- https://master.php.net/note/delete/83178/in+docs
Del: other reasons-- https://master.php.net/note/delete/83178
Reject -- https://master.php.net/note/reject/83178
Search -- https://master.php.net/manage/user-notes.php