我有一個XML與蟒蛇排序XML的標記
<root>
<node1>
<B>text</B>
<A>another_text</A>
<C>one_more_text</C>
</node1>
<node2>
<C>one_more_text</C>
<B>text</B>
<A>another_text</A>
</node2>
</root>
我想要得到的輸出,如:
from xml.etree import ElementTree as et
tr = et.parse(path_in)
root = tr.getroot()
for children in root.getchildren():
for child in children.getchildren():
# sort it
tr.write(path_out)
我不能使用:
<root>
<node1>
<A>another_text</A>
<B>text</B>
<C>one_more_text</C>
</node1>
<node2>
<A>another_text</A>
<B>text</B>
<C>one_more_text</C>
</node2>
</root>
我喜歡的一些代碼試圖標準功能sort
和sorted
,因爲它排序錯誤(而不是標籤)。 在此先感謝。