etree Clone Node

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

    At least in Python 2.7 etree Element has a copy method: http://hg.python.org/cpython/file/2.7/Lib/xml/etree/ElementTree.py#l233

    It is a shallow copy, but that is preferable in some cases.

    In my case I am duplicating some SVG Elements and adding a transform. Duplicating children wouldn't serve any purpose since where relevant they already inherit their parent's transform.

提交回复
热议问题