'Emulate Python 2.3\'s \'xmlcharrefreplace\' encoding error handler.'

def xmlcharref_encode(self, char):

    try:
        return char.encode(self.encoding, 'strict')
    except UnicodeError:
        return ('&#%i;' % ord(char))
