<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def to_etree(source, root_tag=None):
 """ Convert various representations of an XML structure to a etree Element Args: source -- The source object to be converted - ET.Element\ElementTree, dict or string. Keyword args: root_tag -- A optional parent tag in which to wrap the xml tree if no root in dict representation. See dict_to_etree() Returns: A etree Element matching the source object. """

    if hasattr(source, 'get_root'): #XXX:
        return source.get_root()
    elif isinstance(source, type(ET.Element('x'))):    #XXX: # cElementTree.Element isn't exposed directly
        return source
    elif isinstance(source, basestring):
        try:
            return ET.fromstring(source)
        except:
            raise XMLError(source)
    elif hasattr(source, 'keys'):   # Dict.
        return dict_to_etree(source, root_tag)
    else:
        raise XMLError(source)