etree Clone Node

后端 未结 5 1244
慢半拍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:30

    A different, and somewhat disturbing solution:

    new_element = lxml.etree.fromstring(lxml.etree.tostring(elem))
    

提交回复
热议问题