etree Clone Node

后端 未结 5 1242
慢半拍i
慢半拍i 2020-12-30 20:00

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

5条回答
  •  悲哀的现实
    2020-12-30 20:14

    If you have a handle on the Element elem's parent you can call

    new_element = SubElement(parent, elem.tag, elem.attrib)
    

    Otherwise you might want to try

    new_element = makeelement(elem.tag, elem.attrib)
    

    but this is not advised.

提交回复
热议问题