元素树写回磁盘

Element tree writing back to disk

我在 python 中使用

解析了一个大的 xml 文件
tree = ET.parse('test.xml')

#do my manipulation

如何将 xml 文件完全按照我读过的方式写回磁盘,尽管有我的修改。

<?xml version="1.0" encoding="utf-16"?>

这是输入 xml 文件的第一行

我添加了 tree.write("output.sbp", encoding="utf-16"),现在它们大小相同。