dt = minidom.getDOMImplementation('').createDocumentType('html',
    '-//W3C//DTD XHTML 1.0 Strict//EN',
    'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd')
doc.insertBefore(dt, doc.documentElement)
print(doc.toxml())
How to render a doctype with Python's xml.dom.minidom?