Created
May 31, 2011 00:17
-
-
Save gnrfan/999666 to your computer and use it in GitHub Desktop.
Python snippet: Escape unicode characters to be included in XML elements
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 python | |
# -*- encoding: utf8 -*- | |
def escape_unicode_for_xml(str): | |
replacements = ( | |
('<', '<'), | |
('>', '>'), | |
('"', '"'), | |
) | |
for orig, rep in replacements: | |
str = str.replace(orig, rep) | |
return str | |
if __name__ == '__main__': | |
print escape_unicode_for_xml("Juan Pérez") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment