]> git.sesse.net Git - xml-template/blobdiff - php/xml-template.php
Fix some possible attribute issues with the Python code, and make it clean
[xml-template] / php / xml-template.php
index 51f86a56fa1a02cdc90b0cb3220f069b9f92eb89..43132a9af1f369c45f3ab97c47d49203e9170a80 100644 (file)
@@ -33,18 +33,16 @@ function XML_Template_process($node, $obj, $clean = 1)
                        $processed = false;
 
                        if ($child->node_type() == XML_ELEMENT_NODE) {
+                               unset($id);
+
                                $tag = $child->node_name();
                                $attrs = $child->attributes();
                                if (isset($attrs)) {
                                        foreach ($child->attributes() as $attr) {
-                                               // PHP's DOMXML module forgets the prefix information when
-                                               // cloning nodes, so we'll have to avoid the namespace check
-                                               // here, unfortunately
-                                               if (/* $attr->namespace_uri() == 'http://template.sesse.net/' && */ $attr->name() == 'id') {
+                                               if ($attr->namespace_uri() == 'http://template.sesse.net/' && $attr->name() == 'id') {
                                                        $id = $attr->value();
                                                        if ($clean) {
-                                                               // FIXME: this won't work since we're not in the right namespace
-                                                               // $child->remove_attribute($attr->name());
+                                                               $attr->unlink_node();
                                                        }
                                                }
                                        }
@@ -159,7 +157,10 @@ function own_clone_node($node, $doc)
                if (isset($attrs)) {
                        foreach ($node->attributes() as $attr) {
                                $attr2 = $doc->create_attribute($attr->name(), $attr->value());
-                               $attr2->set_namespace($attr->namespace_uri(), $attr->prefix());
+                               $nsuri = $attr->namespace_uri();
+                               if (isset($nsuri)) {
+                                       $attr2->set_namespace($nsuri, $attr->prefix());
+                               }
                                $newnode->append_child($attr2);
                        }
                }