def get_elements_by(xmldoc, *args, **kwargs):
    """Searches xml for nodes with provided tag, attributes (args) and
    attribute key-val pairs (kwargs)

    Args:
        xmldoc (xml.dom.minidom): minidom object (returned by minidom.parse())
        tag (str, optional): name of tag to search for
        *args (str, optional): attribute names to check element has
        **kwargs (str=str, optional): attributeName=attributeValue to check
            element has
    Returns:
        list: returns list of xml.Elements that have given tag, attribute(s)
        and/or attribute key-val(s)
    """
    if 'tag' in kwargs.keys():
        tag = kwargs.pop('tag')
    else:
        tag = None

    if tag is None:  # Get all elements
        tag = '*'
    elements = xmldoc.getElementsByTagName(tag)

    if len(args):
        for a in args:
            elements = [e for e in elements if e.hasAttribute(a)]

    if len(kwargs):
        for k in kwargs.keys():
            elements = [e for e in elements if e.hasAttribute(k) and
                        e.attributes[k].value == kwargs[k]]

    return elements