def escapeToXML(text, isattrib = False):
    text = text.replace("&", "&amp;")
    text = text.replace("<", "&lt;")
    text = text.replace(">", "&gt;")
    if isattrib:
        text = text.replace("'", "&apos;")
        text = text.replace("\"", "&quot;")
    return text
Borrowed from twisted.xish.domish
dataset/ETHPy150Open twisted/nevow/nevow/util.py/escapeToXML