1.增加indent函数
2.增加调用:indent(root,0)
def indent(elem, level=0):
i = "\n" + level*" "
if len(elem):
if not elem.textor not elem.text.strip():
elem.text = i + " "
if not elem.tailor not elem.tail.strip():
elem.tail = i
for elem in elem:
indent(elem, level+1)
if not elem.tailor not elem.tail.strip():
elem.tail = i
else:
if level and (not elem.tailor not elem.tail.strip()):
elem.tail = i