直接写入xml文件,最终得到的xml文件时一行,不是向我们日常看见的换行以及缩进。
文章源自爱尚资源教程网-https://www.23jcw.net/9476.html
为了得到得到上面的效果,需要转换一下,代码如下文章源自爱尚资源教程网-https://www.23jcw.net/9476.html
import xml.etree.ElementTree as ET
from xml.dom import minidom
def saveXML(root, filename, indent="\t", newl="\n", encoding="utf-8"):
rawText = ET.tostring(root)
dom = minidom.parseString(rawText)
with open(filename, 'w') as f:
dom.writexml(f, "", indent, newl, encoding)
文章源自爱尚资源教程网-https://www.23jcw.net/9476.html文章源自爱尚资源教程网-https://www.23jcw.net/9476.html 相关文章
版权声明:文章图片资源来源于网络,如有侵权,请留言删除!!!
