python - How do I change the order of a child element in lxml objectify? -


i have xml order of child elements determines z-order display purposes. use lxml.objectify operate on xml.

how change position of 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 list, modify 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)