def append_string(t, string):
    """Append a string to a node, as text or tail of last child."""
    node = t.tree
    if string:
        if len(node) == 0:
            if node.text is not None:
                node.text += string
            else:
                node.text = string
        else:
            child = list(node)[-1]
            if child.tail is not None:
                child.tail += string
            else:
                child.tail = string
