html = M.html(E.head(E.title('Test page')), E.body(E.p('Hello world')))
result = etree.tostring(html, xml_declaration=True, doctype=
    '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'
    , encoding='utf-8', standalone=False, with_tail=False, method='xml',
    pretty_print=True)
Recommended way to generate XHTML documents with lxml