#NEWLINE# def CreateClassFromXMLString( target_class , xml_string , string_encoding = None ) : #NEWLINE# #INDENT# 'Creates an instance of the target class from the string contents.\n\n  Args:\n    target_class: class The class which will be instantiated and populated\n        with the contents of the XML. This class must have a _tag and a\n        _namespace class variable.\n    xml_string: str A string which contains valid XML. The root element\n        of the XML string should match the tag and namespace of the desired\n        class.\n    string_encoding: str The character encoding which the xml_string should\n        be converted to before it is interpreted and translated into\n        objects. The default is None in which case the string encoding\n        is not changed.\n\n  Returns:\n    An instance of the target class with members assigned according to the\n    contents of the XML - or None if the root XML tag and namespace did not\n    match those of the target class.\n  ' #NEWLINE# encoding = ( string_encoding or XML_STRING_ENCODING ) #NEWLINE# if ( encoding and isinstance ( xml_string , unicode ) ) : #NEWLINE# #INDENT# xml_string = xml_string . encode ( encoding ) #NEWLINE# #UNINDENT# tree = ElementTree . fromstring ( xml_string ) #NEWLINE# return _CreateClassFromElementTree ( target_class , tree )