$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) {
}
# 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);
}
$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->name);
+ $attr2->prefix = $attr->prefix;
}
+ $attr2->value = $attr->value;
$newnode->appendChild($attr2);
}
}
}
return $newnode;
} else {
- return $node->clone_node(true);
+ return $node->cloneNode(true);
}
}