def text_node(tree_or_elem, xpath, onerror=None, ifnone=None):
    """
    Get the text node of the referenced element.

    If the node cannot be found, return `onerror`:
    If the node is found, but its text content is None,
    return ifnone.
    """
    try:
        text = tree_or_elem.find(xpath).text
    except AttributeError:
        text = onerror
    else:
        if text is None:
            text = ifnone
    return text