2012-01-31 14 views

答えて

4

使用toprettyxml又はtoxml方法:例えば

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/>