重新排列节点lxml中的属性

时间:2013-07-31 07:23:14

标签: python python-2.7 lxml elementtree

我有一个像

这样的元素节点
<Relationship Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable" Id="rId61" Target="media/image1.png"/>

我需要按顺序对属性进行排序。输出应该看起来像

<Relationship Id="rId61" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable" Target="media/image1.png"/>

我如何重新安排这个?目前我正在使用lxml库

由于

1 个答案:

答案 0 :(得分:1)

无法使用lxml设置元素属性的特定顺序。 element.attrib是一个字典,python中的字典是无序集合。

另见: