I do have to make copies of nodes in an application I'm writing, so I've
tried making a patch for lxml to allow me to do that. The patch is
attached, but since I don't have experience with Pyrex and libxml2 there
could well be something wrong with it. It seems to work, though.
Also I don't know if creating a new document / _ElementTree for the new
nodes is the right thing to do, but I suppose it should be...
Regards
Florian
Index: src/lxml/etree.pyx
===================================================================
--- src/lxml/etree.pyx (revision 12556)
+++ src/lxml/etree.pyx (working copy)
@@ -370,7 +370,21 @@
c_node = c_node.next
else:
raise ValueError, "Matching element could not be found"
+
+ def copy(self, recursive = True):
+ # 1 = copy recursive; 2 = don't copy recursive
+ recursive = int(not recursive) + 1
+
+ cdef xmlNode* c_node
+ cdef xmlDoc* c_doc
+ c_doc = theParser.newDoc()
+ etree = _elementTreeFactory(c_doc)
+ c_node = tree.xmlDocCopyNode(self._c_node, c_doc, recursive)
+ tree.xmlDocSetRootElement(c_doc, c_node)
+
+ return _elementFactory(etree, c_node)
+
# PROPERTIES
property tag:
def __get__(self):