Python xml.dom.minidom保存时出错
发布网友
发布时间:2022-04-22 23:58
我来回答
共1个回答
热心网友
时间:2023-09-13 23:27
def clear_format(self,fp)
from re import sub as resub
fp=resub('\n','',fp)
fp=resub('\t','',fp)
fp=resub('\s+',' ',fp)
fp=resub('>\s+<','><',fp)
newxml=Dom.parseString(fp)
newfp = newxml.toprettyxml().strip()
return newfp
def __save(self):
with open("Person.xml","w",encoding=self.__doc.encoding) as f:
f=self.clear_format(f)
self.__doc.writexml(f,encoding=self.__doc.encoding)追问Dom.parseString(fp)这个Dom是什么??
追答from xml.dom import minidom as Dom