Я создаю элементы 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>