import xml.dom.minidom as xml
doc = xml.Document()
declaration = doc.toxml()
a = doc.createElement('A')
doc.appendChild(a)
b = doc.createElement('B')
a.appendChild(b)
xml = doc.toprettyxml()[len(declaration):]
print(xml)
How to write an XML file without header in Python?