2012-01-31 100 views

回答

4

使用toprettyxmltoxml方法:

elt.toprettyxml(indent = ' ') 

例如,

import xml.dom.minidom as minidom 
doc = minidom.Document() 
foo = doc.createElement("foo") 
doc.appendChild(foo) 
print(foo.__class__) 
# xml.dom.minidom.Element 

print(foo.toprettyxml(indent = ' ')) 
# <foo/>