Re: [xml] Copying XML subtrees across documents (in Python)

Jos Vos wrote:
What is the recommended way (in the libxml2 Python binding) to copy
a node and all of its children (but not its siblings!) from one
document to another document?

;) the recommended way to use libxml2 from Python is lxml.

I tried (x is a node in the new document, y a node in the old document):

Ok, you want to copy, not move the node, so lxml.etree would do:

   >>> from copy import deepcopy
   >>> x.append(deepcopy(y))

Short and intuitive.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]