def METHOD_NAME(string):
    """
    Escape the string so it's safe to use in XML and xpath.
    """
    entities = {
        "\"": "&quot;",
        "'": "&apos;",
    }
    if isinstance(string, bytes):
        return xml.sax.saxutils.escape(string.decode("utf-8"), entities=entities).encode("utf-8")
    return xml.sax.saxutils.escape(string, entities=entities)