note 99398 added to function.dom-domdocument-renamenode
| From: | attila at roughdot dot nl | Date: | Sun, 15 Aug 2010 10:56:10 +0000 |
| Subject: | note 99398 added to function.dom-domdocument-renamenode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-171685@lists.php.net to get a copy of this message | ||
Try this:
/**
* Renames a node in a dom document.
*
* @param DOMElement $node
* @param string $newName
**/
function renameNode(DOMElement $node, $newName)
{
$newNode = $node->ownerDocument->createElement($newName);
foreach ($node->attributes as $attribute) {
$newNode->setAttribute($attribute->nodeName, $attribute->nodeValue);
}
while ($node->firstChild) {
$newNode->appendChild($node->firstChild);
}
$node->ownerDocument->replaceChild($newNode, $node);
}
As suggested by Matthew Turland (http://matthewturland.com/2010/02/09/renaming-a-domnode-in-php/)
If there is a nicer solution, I would love to hear it!
----
Server IP: 74.208.45.212
Probable Submitter: 195.240.138.20 (proxied: 195.240.138.20)
----
Manual Page -- http://www.php.net/manual/en/function.dom-domdocument-renamenode.php
Edit -- https://master.php.net/note/edit/99398
Del: integrated -- https://master.php.net/note/delete/99398/integrated
Del: useless -- https://master.php.net/note/delete/99398/useless
Del: bad code -- https://master.php.net/note/delete/99398/bad+code
Del: spam -- https://master.php.net/note/delete/99398/spam
Del: non-english -- https://master.php.net/note/delete/99398/non-english
Del: in docs -- https://master.php.net/note/delete/99398/in+docs
Del: other reasons-- https://master.php.net/note/delete/99398
Reject -- https://master.php.net/note/reject/99398
Search -- https://master.php.net/manage/user-notes.php