[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: [xml] Copying XML subtrees across documents (in Python)
- From: Stefan Behnel <stefan_ml behnel de>
- To: Jos Vos <jos xos nl>
- Cc: xml gnome org
- Subject: Re: [xml] Copying XML subtrees across documents (in Python)
- Date: Wed, 18 Jul 2007 11:48:53 +0200
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):
>
> x.addChild(y)
> x.addChild(y.copyNodeList())
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.
Stefan
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]