使用lxml:
from lxml import etree# create XML root = etree.Element('root')root.append(etree.Element('child'))# another child with textchild = etree.Element('child')child.text = 'some text'root.append(child)# pretty strings = etree.tostring(root, pretty_print=True)print s输出:
<root> <child/> <child>some text</child></root>
有关更多信息,请参见教程。



