[英]How do I change the order of a child element in lxml objectify?
我有XML,其中子元素的順序決定了其z順序以用於顯示。 我使用lxml.objectify對XML進行操作。
如何在objectify中更改子元素的位置?
例如更改:
<canvas>
<shape a>
<shape b>
<shape c>
</canvas>
至:
<canvas>
<shape b>
<shape a>
<shape c>
</canvas>
canvas.shape
將是一個列表,因此只需修改列表即可:
from lxml import objectify, etree
canvas = objectify.fromstring('''
<canvas>
<shape name="a" />
<shape name="b" />
<shape name="c" />
</canvas>
''')
canvas.shape = [canvas.shape[1], canvas.shape[0], canvas.shape[2]]
print etree.tostring(canvas, pretty_print=True)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.