def DOM2ET(domelem):
    """Converts a DOM node object of type element to an ElementTree Element.

    domelem: DOM node object of type element (domelem.nodeType == domelem.ELEMENT_NODE)

    returns an 'equivalent' ElementTree Element
    """
    # make some local variables for fast processing
    tyCDATA = domelem.CDATA_SECTION_NODE
    tyTEXT = domelem.TEXT_NODE
    tyPI = domelem.PROCESSING_INSTRUCTION_NODE
    tyCOMMENT = domelem.COMMENT_NODE
    tyELEMENT = domelem.ELEMENT_NODE
    # calculate the attributes of the domelem
    attribs = domelem.attributes
    attrs = dict((x.name, x.value) for x in (attribs.item(i) for i in range(attribs.length)))
    # build the ET Element
    etelem = ET.Element(domelem.tagName, attrs)
    last = None # to differentiate between 'text' and 'tail'
    for node in domelem.childNodes:
        nodeType = node.nodeType
        if (tyTEXT == nodeType or tyCDATA == nodeType) and node.data:
            data = node.data
            if last is None: etelem.text = etelem.text + data if etelem.text else data
            else: last.tail = last.tail + data if last.tail else data
        elif tyELEMENT == nodeType:
            last = DOM2ET(node)
            etelem.append(last)
        elif tyCOMMENT == nodeType:
            last = ET.Comment(node.data)
            etelem.append(last)
        elif tyPI == nodeType:
            last = ET.ProcessingInstruction(node.target, node.data)
            etelem.append(last)

    return etelem
Converts a DOM node object of type element to an ElementTree Element.

    domelem: DOM node object of type element (domelem.nodeType == domelem.ELEMENT_NODE)

    returns an 'equivalent' ElementTree Element
    
recipes/Python/498221_Converts_DOM_node_object_type_element/recipe-498221.py