code: def trim_tree_after(element, include_element=True):
      
      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
docs: 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.