I'm surprised we're grinding the xml out literally rather than using a library like etree. I don't know what different it would make to use a library tho (I'm wondering if it handles the {text} payload better if it has tags and such).