def complex_el_from_dict(parent, data, key):
    """Create element from a dict definition and add it to ``parent``.

    :param parent: parent element
    :type parent: Element
    :param data: dictionary with elements definitions, it can be a simple \
    {element_name: 'element_value'} or complex \
    {element_name: {_attr: {name: value, name1: value1}, _text: 'text'}}
    :param key: element name and key in ``data``
    :return: created element
    """
    el = ET.SubElement(parent, key)
    value = data[key]

    if isinstance(value, dict):
        if '_attr' in value:
            for a_name, a_value in viewitems(value['_attr']):
                el.set(a_name, a_value)

        if '_text' in value:
            el.text = value['_text']

    else:
        el.text = value

    return el
Create element from a dict definition and add it to ``parent``.

    :param parent: parent element
    :type parent: Element
    :param data: dictionary with elements definitions, it can be a simple \
    {element_name: 'element_value'} or complex \
    {element_name: {_attr: {name: value, name1: value1}, _text: 'text'}}
    :param key: element name and key in ``data``
    :return: created element