XML的缩进
从另外一个模块里边提供了缩进功能:
from xml.dom import minidom
def prettify(root):
rough_string=ET.tostring(root,'utf-8')
reparsed=minidom.parseString(rough_string)
return reparsed.toprettyxml(indent="\t")
new_str=prettify(root)
f=open('new_out.xml','w')
f.write(new_str)
f.close()
print(new_str)

注意这个代码可以更牛一点的:
def MyWrite(root,file_path):
rough_string=ET.tostring(root,'utf-8')
reparsed=minidom.parseString(rough_string)
new_str= reparsed.toprettyxml(indent="\t")
f=open(file_path,'w')
f.write(new_str)
f.close()


浙公网安备 33010602011771号