with open(outxml, 'w') as out:
    valid_xmlstring = mystring.encode('latin1', 'xmlcharrefreplace').decode(
        'utf8', 'xmlcharrefreplace')
out.write(valid_xmlstring)
Parsing huge, badly encoded XML files in Python