RE_XML_ENCODING = re.compile(
    '^(<\\?xml[^>]+)\\s+encoding\\s*=\\s*["\\\'][^"\\\']*["\\\'](\\s*\\?>|)',
    re.U)
RE_XML_ENCODING.sub('', broken_xml_string, count=1)
Is there a way to force lxml to parse Unicode strings that specify an encoding in a tag?