def get_node_string(node_formatter, node):
    """
    Returns a string for the specified node and its children, converted
    with the specified formatter. Based on
    serifxml.SerifSynNodeTheory._treebank_str.
    """

    # Terminal nodes just get formatted
    if len(node) == 0:
        return node_formatter(node)

    # Non-terminal nodes get their tag and their formatted children
    node_string = "(%s" % node.tag
    node_string += "".join([" %s" % get_node_string(node_formatter, child) for child in node])
    node_string += ")"
    return node_string