2

子要素の順序によって表示目的の z オーダーが決定される XML があります。lxml.objectify を使用して XML を操作します。

objectify で子要素の位置を変更するにはどうすればよいですか?

例:

<canvas>
  <shape a>
  <shape b>
  <shape c>
</canvas>

に:

<canvas>
  <shape b>
  <shape a>
  <shape c>
</canvas>
4

1 に答える 1

2

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)
于 2013-08-23T03:03:23.307 に答える