X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=php5%2Fxml-template.php;h=b6f4041c2cf45ae81435edfa29187594ec2b793b;hb=99016a84873203454b833a70e2cef574cd14a184;hp=e6f92c21888135ef9038a9d79965a85f7d67a5aa;hpb=19ada1f1ca1872cfe3210d62b0633702b8d46f51;p=xml-template diff --git a/php5/xml-template.php b/php5/xml-template.php index e6f92c2..b6f4041 100644 --- a/php5/xml-template.php +++ b/php5/xml-template.php @@ -46,7 +46,7 @@ function XML_Template_process($node, $obj, $clean = 1) if ($attr->namespaceURI == 'http://template.sesse.net/' && $attr->name == 'id') { $id = $attr->value; if ($clean) { - # $attr->unlinkNode(); + $child->removeAttributeNode($attr); } } } @@ -79,10 +79,9 @@ function XML_Template_process($node, $obj, $clean = 1) $doc = $node->ownerDocument; $frag = $doc->createElement("temporary-fragment"); # ugh - for ($i = 0; $i < $node->childNodes->length; ++$i) { - $child = $node->childNodes->item($i); + while ($node->childNodes->length > 0) { + $child = $node->childNodes->item(0); $frag->appendChild($child); - $node->removeChild($child); } foreach ($obj as $instance) { @@ -153,15 +152,16 @@ function XML_Template_alternate($tag, $array, $elems) } # Ideally, this would be "return $obj->clone_node(true)". But surprise, surprise, -# PHP is buggy (at least PHP4); it removes the prefix information from all attributes -# during a clone. IOW, we'll have to clone evverything ourselves. +# 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()); + $newnode = $doc->createElementNS($node->namespaceURI, $node->nodeName, $node->prefix); } else { $newnode = $doc->createElement($node->nodeName); } @@ -169,11 +169,13 @@ function own_clone_node($node, $doc) $attrs = $node->attributes; if (isset($attrs)) { foreach ($node->attributes as $attr) { - $attr2 = $doc->createAttribute($attr->name, $attr->value); $nsuri = $attr->namespaceURI; if (isset($nsuri)) { - $attr2->set_namespace($nsuri, $attr->prefix); + $attr2 = $doc->createAttribute($attr->name); + } else { + $attr2 = $doc->createAttributeNS($nsuri, $attr->prefix . ":" . $attr->name); } + $attr2->value = $attr->value; $newnode->appendChild($attr2); } } @@ -183,7 +185,7 @@ function own_clone_node($node, $doc) } return $newnode; } else { - return $node->clone_node(true); + return $node->cloneNode(true); } }