Skip to content

Instantly share code, notes, and snippets.

@filipkral
Last active August 29, 2015 14:03
Show Gist options
  • Save filipkral/68523971717a0d88a3cf to your computer and use it in GitHub Desktop.
Save filipkral/68523971717a0d88a3cf to your computer and use it in GitHub Desktop.
Convert XML codes from Unicode to string and back in Python
# How to convert XML codes for Unicode can be translated to Unicode in Python
# This is useful for example when reading/writing from/to attribute tables in ArcGIS
import HTMLParser
parser = HTMLParser.HTMLParser()
unescaped = parser.unescape('Krinelnàch')
# To convert from Unicode to xml do:
escaped = u'Krineln\xe0ch'.encode('ascii', 'xmlcharrefreplace')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment