def safedata(self, data, cdata=True):
        r"""Convert xml special chars to entities.

        :param data: the data will be converted safe.
        :param cdata: whether to use cdata. Default：``True``. If not, use :func:`cgi.escape` to convert data.
        :type cdata: bool
        :rtype: str
        """
        safe = ('<![CDATA[%s]]>' % data) if cdata else cgi.escape(str(data), True)
        return safe