我正在创建XML元素并对其进行预打印,如图所示:
rootElement = Element("root)
childElement = SubElement(rootElement, "child")
def prettify(elem):
rough_string = ElementTree.tostring(elem, 'utf-8')
reparsed = minidom.parseString(rough_string)
return reparsed.toprettyxml(indent=" ")
print prettify(rootElement)
输出看起来像
<?xml version="1.0" ?>
<root>
<child/>
</root>
如何在这些元素之间添加其他行?你知道吗
<?xml version="1.0" ?>
<root>
<!-- how to add line spaces here -->
<child/>
</root>
官方文件说
newl
参数处理行距。所以你可以给一个或多个行空间来做这个。你知道吗相关问题 更多 >
编程相关推荐