From: sgunderson@bigfoot.com <> Date: Mon, 21 Apr 2008 20:13:17 +0000 (+0200) Subject: Let's see if cloneNode() is fixed after all... X-Git-Url: https://git.sesse.net/?p=xml-template;a=commitdiff_plain;h=81500cd7f6be3775d5c5f7322a55874e9d691585 Let's see if cloneNode() is fixed after all... --- diff --git a/php5/xml-template.php b/php5/xml-template.php index 08c78ab..f69fbca 100644 --- a/php5/xml-template.php +++ b/php5/xml-template.php @@ -20,7 +20,7 @@ function XML_Template_process($node, $obj, $clean = 1) $obj = $obj->document_element(); } - $newobj = own_clone_node($obj, $node->ownerDocument); + $newobj = $obj->cloneNode(true); $node->appendChild($newobj); XML_Template_process($newobj, array(), $clean); @@ -90,7 +90,7 @@ function XML_Template_process($node, $obj, $clean = 1) continue; } - $newnode = own_clone_node($frag, $frag->ownerDocument); + $newnode = $frag->cloneNode(true); $node->appendChild($newnode); XML_Template_process($newnode, $instance, $clean); if ($clean) { @@ -153,44 +153,6 @@ function XML_Template_alternate($tag, $array, $elems) return $array; } -# Ideally, this would be "return $obj->clone_node(true)". But surprise, surprise, -# PHP is buggy (at least both PHP4 and PHP5); it removes the prefix information -# from all attributes during a clone. IOW, we'll have to clone evverything -# ourselves. -function own_clone_node($node, $doc) -{ - // we only need these two - if ($node->nodeType == XML_ELEMENT_NODE) { - $nsuri = $node->namespaceURI; - if (isset($nsuri)) { - $newnode = $doc->createElementNS($node->namespaceURI, $node->nodeName, $node->prefix); - } else { - $newnode = $doc->createElement($node->nodeName); - } - - $attrs = $node->attributes; - if (isset($attrs)) { - foreach ($node->attributes as $attr) { - $nsuri = $attr->namespaceURI; - if (isset($nsuri)) { - $attr2 = $doc->createAttribute($attr->name); - } else { - $attr2 = $doc->createAttributeNS($nsuri, $attr->prefix . ":" . $attr->name); - } - $attr2->value = $attr->value; - $newnode->appendChild($attr2); - } - } - for ($i = 0; $i < $node->childNodes->length; ++$i) { - $child = $node->childNodes->item($i); - $newnode->appendChild(own_clone_node($child, $doc)); - } - return $newnode; - } else { - return $node->cloneNode(true); - } -} - function is_associative_array($arr) { if (!is_array($arr)) {