def xmlparser(xml, objectify=True):
    """ Parse xml

    :param xml: XML element
    :type xml: Union[text_type, lxml.etree._Element]
    :rtype: lxml.etree._Element
    :returns: An element object
    :raises: TypeError if element is not in accepted type

    """
    doclose = None
    if isinstance(xml, (etree._Element, ObjectifiedElement, etree._ElementTree)):
        return xml
    elif isinstance(xml, text_type):
        xml = StringIO(xml)
        doclose = True
    elif not isinstance(xml, IOBase):
        raise TypeError("Unsupported type of resource {}".format(type(xml)))

    if objectify is False:
        parsed = etree.parse(xml).getroot()
    else:
        parsed = parse(xml).getroot()
    if doclose:
        xml.close()
    return parsed
def xmlparser ( xml , objectify = True ) : doclose = None if isinstance ( xml , ( etree . _Element , ObjectifiedElement , etree . _ElementTree ) ) : return xml elif isinstance ( xml , text_type ) : xml = StringIO ( xml ) doclose = True elif not isinstance ( xml , IOBase ) : raise TypeError ( "Unsupported type of resource {}" . format ( type ( xml ) ) ) if objectify is False : parsed = etree . parse ( xml ) . getroot ( ) else : parsed = parse ( xml ) . getroot ( ) if doclose : xml . close ( ) return parsed
Parse xml

    :param xml: XML element
    :type xml: Union[text_type, lxml.etree._Element]
    :rtype: lxml.etree._Element
    :returns: An element object
    :raises: TypeError if element is not in accepted type