'Adds a child element to the specified element.
The element to whom to add the new element is specified using ``source``
and ``xpath``. They have exactly the same semantics as with `Get Element`
keyword. The resulting XML structure is returned, and if the ``source``
is an already parsed XML structure, it is also modified in place.
The ``element`` to add can be specified as a path to an XML file or
as a string containing XML, or it can be an already parsed XML element.
The element is copied before adding so modifying either the original
or the added element has no effect on the other
The element is added as the last child by default, but a custom index
can be used to alter the position. Indices start from zero (0 = first
position, 1 = second position, etc.), and negative numbers refer to
positions at the end (-1 = second last position, -2 = third last, etc.).
Examples using ``${XML}`` structure from `Example`:
| Add Element | ${XML} | <new id="x"><c1/></new> |
| Add Element | ${XML} | <c2/> | xpath=new |
| Add Element | ${XML} | <c3/> | index=1 | xpath=new |
| ${new} = | Get Element | ${XML} | new |
| Elements Should Be Equal | ${new} | <new id="x"><c1/><c3/><c2/></new> |
Use `Remove Element` or `Remove Elements` to remove elements.'

def add_element(self, source, element, index=None, xpath='.'):

    source = self.get_element(source)
    parent = self.get_element(source, xpath)
    element = self.copy_element(element)
    if (index is None):
        parent.append(element)
    else:
        parent.insert(int(index), element)
    return source
