def remove_invalid_xml_chars(val):
    """
    Remove characters which aren't allowed in XML.
    :param val:
    :return:
    """
    val = make_utf8(val)
    val = re.sub(u'[^\u0020-\uD7FF\u0009\u000A\u000D\uE000-\uFFFD\U00010000-\U0010FFFF]+', '?', val)
    return val