import copy


def nested_element(element, depth):
  """Makes a nested `tree.Element` given a single element.

  If `depth=2`, the new tree will look like

  ```xml
  <element>
    <element>
      <element>
      </element>
    </element>
  </element>
  ```

  Args:
    element: The `etree.Element` used to create a nested structure.
    depth: An `int` denoting the nesting depth. The resulting will contain
      `element` nested `depth` times.


  Returns:
    A nested `etree.Element`.
  """
  if depth > 0:
    child = nested_element(copy.deepcopy(element), depth=(depth - 1))
    element.append(child)
  return element