子要素の順序によって表示目的の z オーダーが決定される XML があります。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)