def trim_tree_after(element, include_element=True):
    """
    Removes the document tree following the given element. If include_element
    is True, the given element is kept in the tree, otherwise it is removed.
    """
    el = element
    for parent_el in element.iterancestors():
        el.tail = None
        if el != element or include_element:
            el = el.getnext()
        while el is not None:
            remove_el = el
            el = el.getnext()
            parent_el.remove(remove_el)
        el = parent_el
Removes the document tree following the given element. If include_element
    is True, the given element is kept in the tree, otherwise it is removed.