'Changes a MS smart quote character to an XML or HTML
entity.'

def subMSChar(orig, smartQuotesTo):

    sub = UnicodeDammit.MS_CHARS.get(orig)
    if isinstance(sub, types.TupleType):
        if (smartQuotesTo == 'xml'):
            sub = ('&#x%s;' % sub[1])
        elif (smartQuotesTo == 'html'):
            sub = ('&%s;' % sub[0])
        else:
            sub = unichr(int(sub[1], 16))
    return sub
