def delete_node_by_xpath(mapping, xpath, ignore_errors=False):
    """Delete the node pointed to by xpath from mapping.

    Args:
        mapping: nested dictionary.
        xpath: string-like selector.
        ignore_errors: if True, pass silently if the node doesn't exist,
            otherwise, raise an exception.

    Example:

    >>> tree = {'level1': {'level2': {'level3': 'bottom'}}}
    >>> delete_node_by_xpath(tree, 'level1.level2')
    >>> tree
    {'level1': {}}

    """
    segments = xpath.split('.')
    attrname = segments.pop()
    for segment in segments:
        if segment not in mapping:
            if ignore_errors:
                return
            raise KeyError(
                "Invalid '{}' selector: '{}' doesn't match anything.".
                format(xpath, segment))
        mapping = mapping[segment]
    return mapping.pop(attrname, None)
