1. 读取后保存格式不统一问题
读取时需自定义解析器添加remove_blank_text=True
来移除原文件的空格
这样保存的时候pretty_print=True
才会真正有效
参考: https://blog.csdn.net/xcookies/article/details/78647242
parser = etree.XMLParser(remove_blank_text=True)
tree = etree.parse(filename, parser)
root = tree.getroot()
# some operation
# ...
tree.write(outpath, pretty_print=True, xml_declaration=True, encoding='utf-8')
网友评论