note 50500 added to function.dom-domnode-replacechild
| From: | jb at jbpros dot com | Date: | Wed, 02 Mar 2005 04:08:12 +0000 |
| Subject: | note 50500 added to function.dom-domnode-replacechild | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-85762@lists.php.net to get a copy of this message | ||
About the problem of replacing more than one child, there is an easier solution than what <roland
dot swingler at transversal dot com> proposed. Instead of a normal iteration, just use a
regressive loop.
<?php
$xml = new DOMDocument;
$xml->load('docfile.xml');
$elements = $xml->getElementsByTagNameNS('http://www.example.com/NS/', '*');
$i = $elements->length - 1;
while ($i > -1) {
$element = $elements->item($i);
$ignore = false;
$newelement = $xml>createTextNode('Some new node!');
$element->parentNode->replaceChild($newelement, $element);
$i--;
}
?>
The loop counter ($i) will always be in the list's interval as removed elements indexes are
above the counter.
----
Manual Page -- http://www.php.net/manual/en/function.dom-domnode-replacechild.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+50500
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50500&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50500&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50500&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50500&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50500&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+50500&report=yes
Search -- http://master.php.net/manage/user-notes.php