def xml_to_json(element, definition, required=False):<EOL>
<EOL>if isinstance(definition, str) and len(definition) > <NUM_LIT:0>:<EOL><INDENT>if definition[<NUM_LIT:0>] == '<STR_LIT:@>':  <EOL><INDENT>return element.get(definition[<NUM_LIT:1>:])<EOL><DEDENT>else:<EOL><INDENT>sub_element = element.find(definition)<EOL>if sub_element is None:<EOL><INDENT>if required:<EOL><INDENT>raise NotCompleteXmlException('<STR_LIT>'.format(definition, element.tag))<EOL><DEDENT>return None<EOL><DEDENT>return sub_element.text.strip() if sub_element.text else None<EOL><DEDENT><DEDENT>elif isinstance(definition, tuple):<EOL><INDENT>return _parse_tuple(element, definition, required)<EOL><DEDENT>elif isinstance(definition, dict):<EOL><INDENT>return _parse_dict(element, definition)<EOL><DEDENT>elif isinstance(definition, list):<EOL><INDENT>return _parse_list(element, definition)<EOL><DEDENT>elif hasattr(definition, '<STR_LIT>'):<EOL><INDENT>return definition(element)<EOL><DEDENT>else:<EOL><INDENT>return element.text.strip() if element.text else None<EOL><DEDENT>
Convert XML (ElementTree) to dictionary from a definition schema.

    Definition schema can be a simple string - XPath or @attribute for
    direct extraction or a complex one described by

    * dictionary ``{key: 'xpath or @attribute', second: 'complex definition'}`` \
      required parameters can be marked with * at the end
    * list ``[xpath, [definition]]`` - create a list of all elements found by \
      xpath, parse the parts with given definition if provided as second \
      argument
    * Callable - parse the element by given function, can be handy as a part \
      of complex definition

    :param element: ElementTree element
    :type element: ElementTree.Element
    :param definition: schema for the json
    :type definition: Union[str, tuple, dict, list, Callable]
    :param required: parsed value should be not None
    :type required: bool
    :return: parsed xml
    :rtype: Union[dict, str, list]