def flatten_tokens(dom):
    """Flattens <token> nodes in DOM"""

    # Modify the DOM, flattening <token>s
    # './/*token' does not find <token>s that are children of <doc>
    
    for node in dom.findall('.//token'):

        # Flatten the children of <token> with \t
        flat = "\t".join(node.itertext())

        # Clean the children
        for child in list(node):
            node.remove(child)

        node.text = flat +  '\n'

    # Flatten DOM and return:
    return dom