note 103145 added to class.domelement

From: Date: Tue, 29 Mar 2011 00:49:14 +0000
Subject: note 103145 added to class.domelement
Groups: php.notes 
Request: Send a blank email to php-notes+get-178284@lists.php.net to get a copy of this message
You want to change the tag name of an element in a DOM tree, preserving the structure of its hierarchy of children? Well for applications like translating custom tags to "real" html I've found the following quickest: <?php $Document; // The DOM Document $Element; // The troublesome element of the document requiring translation $NewElement = $Document->createElement('newtagname'); // Clone the attributes: foreach($Element->attributes as $attribute) $NewElement->setAttribute($attribute->name, $attribute->value); // Add clones of the old element's children to the replacement foreach($Element->childNodes as $child) $NewElement->appendChild($child->cloneNode(true)); // Replace the old node $Element->parentNode->replaceChild($NewElement, $Element); ?> ---- Server IP: 69.147.83.197 Probable Submitter: 88.110.244.14 ---- Manual Page -- http://www.php.net/manual/en/class.domelement.php Edit -- https://master.php.net/note/edit/103145 Del: integrated -- https://master.php.net/note/delete/103145/integrated Del: useless -- https://master.php.net/note/delete/103145/useless Del: bad code -- https://master.php.net/note/delete/103145/bad+code Del: spam -- https://master.php.net/note/delete/103145/spam Del: non-english -- https://master.php.net/note/delete/103145/non-english Del: in docs -- https://master.php.net/note/delete/103145/in+docs Del: other reasons-- https://master.php.net/note/delete/103145 Reject -- https://master.php.net/note/reject/103145 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#178284) next »