私はxmlファイルを持っていて、それに要素を追加しようとしています。xml には次の構造があります。
<root>
<OldNode/>
</root>
私が探しているのは:
<root>
<OldNode/>
<NewNode/>
</root>
しかし、実際には次のxmlを取得しています:
<root>
<OldNode/>
</root>
<root>
<OldNode/>
<NewNode/>
</root>
私のコードは次のようになります:
file = open("/tmp/" + executionID +".xml", 'a')
xmlRoot = xml.parse("/tmp/" + executionID +".xml").getroot()
child = xml.Element("NewNode")
xmlRoot.append(child)
xml.ElementTree(root).write(file)
file.close()
ありがとう。