note 112081 added to function.dom-domdocument-renamenode
| From: | hanskrentel at yahoo dot de | Date: | Tue, 30 Apr 2013 19:52:41 +0000 |
| Subject: | note 112081 added to function.dom-domdocument-renamenode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-194672@lists.php.net to get a copy of this message | ||
The previous given function was not so useable because of giving errors. It was trivial to fix. It
could also be improved by returning the old node, because technically this does not rename but
replaces with a renamed node.
<?php
/**
* Renames a node in a DOM Document.
*
* @param DOMElement $node
* @param string $name
*
* @return DOMNode
*/
function dom_rename_element(DOMElement $node, $name) {
$renamed = $node->ownerDocument->createElement($name);
foreach ($node->attributes as $attribute) {
$renamed->setAttribute($attribute->nodeName, $attribute->nodeValue);
}
while ($node->firstChild) {
$renamed->appendChild($node->firstChild);
}
return $node->parentNode->replaceChild($renamed, $node);
}
----
Server IP: 134.129.167.88
Probable Submitter: 84.132.125.165
----
Manual Page -- http://php.net/manual/en/function.dom-domdocument-renamenode.php
Edit -- https://master.php.net/note/edit/112081
Del: integrated -- https://master.php.net/note/delete/112081/integrated
Del: useless -- https://master.php.net/note/delete/112081/useless
Del: bad code -- https://master.php.net/note/delete/112081/bad+code
Del: spam -- https://master.php.net/note/delete/112081/spam
Del: non-english -- https://master.php.net/note/delete/112081/non-english
Del: in docs -- https://master.php.net/note/delete/112081/in+docs
Del: other reasons-- https://master.php.net/note/delete/112081
Reject -- https://master.php.net/note/reject/112081
Search -- https://master.php.net/manage/user-notes.php