使用python在elementtree write的输出中交换属性place

2024-06-24 11:40:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用元素树和python来保存xml文件。我只是在某个节点之后插入新节点。我没有修改任何属性。逻辑工作正常,新节点被添加到适当的位置。但是在输出中,节点属性的位置正在交换,如下所示:

输入

<set title="Set Testcase1 to 128">
  <testvariable name="Testcase1" msg="TEST" node="TESTER" testtype="METHOD1">128</testvariable>
</set>
<match **title="match" timeout="220"**>
  <testvariable name="Testcase1" msg="TEST" node="TESTER" **testtype="METHOD1"**>128</testvariable>
</match>

输出

<set title="Set Testcase1 to 128">
  <testvariable testtype="METHOD1" msg="TEST" name="Testcase1" node="TESTER">128</testvariable>
</set>
<match timeout="220" title="match">
  <testvariable testtype="METHOD1" msg="TEST" name="Testcase1" node="TESTER">128</testvariable>
</match>

对输出的写入通过以下方式完成: tree.write(r'textOut.xml',encoding="iso-8859-1")

任何人都请让我知道为什么属性的地方互换

先谢谢你


Tags: nametestnode属性节点titlematchmsg