[Lxml-checkins] r35615 - lxml/branch/nscleanup/src/lxml

scoder at codespeak.net scoder at codespeak.net
Tue Dec 12 10:44:16 CET 2006


Author: scoder
Date: Tue Dec 12 10:44:12 2006
New Revision: 35615

Modified:
   lxml/branch/nscleanup/src/lxml/proxy.pxi
Log:
fix for namespace cleanup

Modified: lxml/branch/nscleanup/src/lxml/proxy.pxi
==============================================================================
--- lxml/branch/nscleanup/src/lxml/proxy.pxi	(original)
+++ lxml/branch/nscleanup/src/lxml/proxy.pxi	Tue Dec 12 10:44:12 2006
@@ -45,30 +45,31 @@
     # always call _destroyFakeDoc() after use!
     cdef xmlNode* c_child
     cdef xmlNode* c_root
+    cdef xmlNode* c_new_root
     cdef xmlDoc*  c_doc
     c_root = tree.xmlDocGetRootElement(c_base_doc)
     if c_root is c_node:
         # already the root node
         return c_base_doc
 
-    c_doc  = _copyDoc(c_base_doc, 0)               # non recursive!
-    c_root = tree.xmlDocCopyNode(c_node, c_doc, 2) # non recursive!
-    tree.xmlDocSetRootElement(c_doc, c_root)
-
-    c_root.children = c_node.children
-    c_root.last = c_node.last
-    c_root.next = c_root.prev = c_root.parent = NULL
+    c_doc  = _copyDoc(c_base_doc, 0)                   # non recursive!
+    c_new_root = tree.xmlDocCopyNode(c_node, c_doc, 2) # non recursive!
+    tree.xmlDocSetRootElement(c_doc, c_new_root)
+
+    c_new_root.children = c_node.children
+    c_new_root.last = c_node.last
+    c_new_root.next = c_new_root.prev = c_new_root.parent = NULL
 
     # store original node
     c_doc._private = c_node
 
     # divert parent pointers of children
-    c_child = c_root.children
+    c_child = c_new_root.children
     while c_child is not NULL:
-        c_child.parent = c_root
+        c_child.parent = c_new_root
         c_child = c_child.next
 
-    c_doc.children = c_root
+    c_doc.children = c_new_root
     return c_doc
 
 cdef void _destroyFakeDoc(xmlDoc* c_base_doc, xmlDoc* c_doc):
@@ -219,20 +220,27 @@
     c_cache_last = 0
 
     while c_element is not NULL:
-        # remove namespaces defined here if already known in ancestors
+        # remove namespaces defined here that are known in the new ancestors
         if c_element.nsDef is not NULL:
-            while c_element.nsDef is not NULL and \
-                      tree.xmlSearchNsByHref(c_element.doc, c_element.parent,
-                                             c_element.nsDef.href) is not NULL:
+            while c_element.nsDef is not NULL:
+                c_ns = tree.xmlSearchNsByHref(
+                    c_element.doc, c_element.parent, c_element.nsDef.href)
+                if c_ns is NULL:
+                    break
                 c_element.nsDef = c_element.nsDef.next
             if c_element.nsDef is not NULL:
-                c_ns = c_element.nsDef
-                while c_ns.next is not NULL:
-                    if tree.xmlSearchNsByHref(c_element.doc, c_element.parent,
-                                              c_ns.next.href) is not NULL:
-                        c_ns.next = c_ns.next.next
+                c_new_ns = c_element.nsDef
+                while c_new_ns.next is not NULL:
+                    if c_new_ns.next is not c_element.ns:
+                        c_ns = tree.xmlSearchNsByHref(
+                            c_element.doc, c_element.parent, c_new_ns.next.href)
+                        if c_ns is not NULL:
+                            # not known or at least not different
+                            c_new_ns.next = c_new_ns.next.next
+                        else:
+                            c_new_ns = c_new_ns.next
                     else:
-                        c_ns = c_ns.next
+                        c_new_ns = c_new_ns.next
 
         # make sure the namespace of an element and its attributes is declared
         # in this document


More information about the lxml-checkins mailing list