def complex_el_from_dict(parent, data, key):
el = ET.SubElement(parent, key)<EOL>value = data[key]<EOL>if isinstance(value, dict):<EOL><INDENT>if '<STR_LIT>' in value:<EOL><INDENT>for a_name, a_value in viewitems(value['<STR_LIT>']):<EOL><INDENT>el.set(a_name, a_value)<EOL><DEDENT><DEDENT>if '<STR_LIT>' in value:<EOL><INDENT>el.text = value['<STR_LIT>']<EOL><DEDENT><DEDENT>else:<EOL><INDENT>el.text = value<EOL><DEDENT>return el<EOL>
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