def xml_str(s):
 encoded_str = smart_str(s, encoding='utf8', errors='xmlcharrefreplace')
 encoded_str = re.sub(INVALID_XML, '?', encoded_str)
 return encoded_str

def xml_str ( s ) : encoded_str = smart_str ( s , encoding = 'utf8' , errors = 'xmlcharrefreplace' ) encoded_str = re . sub ( INVALID_XML , '?' , encoded_str ) return encoded_str
avoid encoding errors while generating objects utf8 byte-string representations .