I have XML where the order of the child elements determines their z-order for display purposes. I use lxml.objectify to operate on the XML.
How do I change the position of a child element in objectify?
E.g. change:
<canvas>
<shape a>
<shape b>
<shape c>
</canvas>
To:
<canvas>
<shape b>
<shape a>
<shape c>
</canvas>
canvas.shape will be a list, so just modify the list:
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With