]> git.sesse.net Git - xml-template/commitdiff
Fix much of the cloning.
authorsgunderson@bigfoot.com <>
Wed, 6 Sep 2006 15:48:41 +0000 (17:48 +0200)
committersgunderson@bigfoot.com <>
Wed, 6 Sep 2006 15:48:41 +0000 (17:48 +0200)
python/xmltemplate.py

index cac93b717c4f3b35d97e1a647fc6a2b646d098ad..edffea78e21f243d07e7e3bb7a944cb8e61a29c5 100644 (file)
@@ -50,11 +50,10 @@ def process(node, obj, clean = True):
                doc = _get_document_element(node)
                frag = doc.createElement("temporary-fragment")     # ugh
 
-               for child in node.childNodes:
-                       frag.appendChild(child)
-               
-               for child in node.childNodes:
+               while not node.firstChild is None:
+                       child = node.firstChild
                        node.removeChild(child)
+                       frag.appendChild(child)
 
                for instance in obj:
                        newnode = frag.cloneNode(True)
@@ -65,11 +64,17 @@ def process(node, obj, clean = True):
 
                # remove all the <fragment> tags
 
+               children_to_remove = []
                for child in node.childNodes:
                        if isinstance(child, xml.dom.minidom.Element) and child.tagName == 'temporary-fragment':
-                               for child2 in child.childNodes:
+                               while not child.firstChild is None:
+                                       child2 = child.firstChild
+                                       child.removeChild(child2)
                                        node.appendChild(child2)
-                               node.removeChild(child)
+                               children_to_remove.append(child)
+
+               for child in children_to_remove:
+                       node.removeChild(child)
 
        if clean:
                _clean(node)