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 -- http://mail.python.org/mailman/listinfo/python-list