Created
October 28, 2009 15:24
-
-
Save arnaudsj/220537 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2.6 | |
# -*- coding: utf-8 -*- | |
""" | |
Code snippet that shows how to convert a utf-8 encoded string to an XML decimal entity string | |
""" | |
from xml.sax import saxutils | |
import codecs | |
if __name__ == "__main__": | |
# Example string to convert | |
s = "Пожалуйста, ответьте на все вопросы, выделенные красным, прежде чем отправлять свой отзыв. Спасибо!" | |
# For the output to be us-ascii | |
enc = codecs.getencoder('us-ascii') | |
# Perform the re-encoding | |
print enc(saxutils.escape(s).decode('utf-8','ignore'), 'xmlcharrefreplace')[0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment