def XMLescape(txt):
    """Returns provided string with symbols & < > " replaced by their respective XML entities."""
    # replace also FORM FEED and ESC, because they are not valid XML chars
    return txt.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;").replace('"', "&quot;").replace(u'\x0C', "").replace(u'\x1B', "")
Returns provided string with symbols & < > " replaced by their respective XML entities.
chrome-cordova/gcmServer/xmpp/simplexml.py