def _build_xpath_expression(tag, attribute_value_dict, direct_children_only=False):
    """
    Returns an XPath expressiong string based on the XML tag and attributes/values provided
    :param tag: XML Tag of the desired object
    :type tag: str
    :param attribute_value_dict: Dictionary containing desired attribute, value pairs to match. Optional
    :type attribute_value_dict: dict
    :param direct_children_only: Optional. if set to True, XPath expression will be limited to direct-children nodes only
    :type direct_children_only: bool
    """  
    xpath_expr =  ("./" + tag) if (direct_children_only==True) else (".//" + tag)
    
    if(len(attribute_value_dict) > 0 and type(attribute_value_dict) == dict):
        attr_value_pairs = []
        for attr, val in attribute_value_dict.items(): #combine all pairs as xpath and append to list
            if(val == None):
                attr_value_pairs.append('@' + attr)
            else:
                attr_value_pairs.append('@' + attr + '="' + val +'"')
        attr_xpath_expr = " and ".join(attr_value_pairs)
        xpath_expr += '[' + attr_xpath_expr + ']'
    return xpath_expr