ElementTree and clone element toot
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Mon Feb 2 10:18:08 EST 2009
En Mon, 02 Feb 2009 12:37:36 -0200, Gerard Flanagan <grflanagan at gmail.com>
escribió:
> e = ET.fromstring(s)
>
> def clone(elem):
> ret = elem.makeelement(elem.tag, elem.attrib)
> ret.text = elem.text
> for child in elem:
> ret.append(clone(child))
> return ret
>
> f = clone(e)
You forget the tail attribute, and you also should use the SubElement
factory instead of makeelement as documented; doing that fixes the
"parent" issue too.
--
Gabriel Genellina
More information about the Python-list
mailing list