def get_root(node):
    """Navigates up the given node and returns the root node."""
    try:
        while node.parent:
            node = node.parent
    except AttributeError:
        pass
    return node
