etree Clone Node

Ming-Tang picture Ming-Tang · Oct 23, 2010 · Viewed 26.3k times · Source

How to clone Element objects in Python xml.etree? I'm trying to procedurally move and copy (then modify their attributes) nodes.

Answer

Steven picture Steven · Oct 23, 2010

You can just use copy.deepcopy() to make a copy of the element. (this will also work with lxml by the way).