Last active
August 29, 2015 14:03
-
-
Save filipkral/68523971717a0d88a3cf to your computer and use it in GitHub Desktop.
Convert XML codes from Unicode to string and back in Python
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
# 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