docs: def remove_empty_element(parent_to_parse, element_path, target_element=None):
      """
      Searches for all empty sub-elements named after element_name in the parsed element,
      and if it exists, removes them all and returns them as a list.
      """
  
      element = get_element(parent_to_parse)
      removed = []
  
      if element is None or not element_path:
          return removed
  
      if target_element:
  
          # Always deal with just the element path
          if not element_path.endswith(target_element):
              element_path = XPATH_DELIM.join([element_path, target_element])
          target_element = None
  
      if XPATH_DELIM not in element_path:
  
          # Loop over and remove empty sub-elements directly
          for subelem in get_elements(element, element_path):
              if element_is_empty(subelem):
                  removed.append(subelem)
                  element.remove(subelem)
      else:
          # Parse target element from last node in element path
          xpath_segments = element_path.split(XPATH_DELIM)
          element_path = XPATH_DELIM.join(xpath_segments[:-1])
          target_element = xpath_segments[-1]
  
          # Loop over children and remove empty ones directly
          for parent in get_elements(element, element_path):
              for child in get_elements(parent, target_element):
                  if element_is_empty(child):
                      removed.append(child)
                      parent.remove(child)
  
              # Parent may be empty now: recursively remove empty elements in XPATH
              if element_is_empty(parent):
                  if len(xpath_segments) == 2:
                      removed.extend(remove_empty_element(element, xpath_segments[0]))
                  else:
                      next_element_path = XPATH_DELIM.join(xpath_segments[:-2])
                      next_target_element = parent.tag
  
                      removed.extend(remove_empty_element(element, next_element_path, next_target_element))
  
      return removed