Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
To filter invalid XML characters in python
#Based on an answer by John Machin on Stack Overflow (http://stackoverflow.com/users/84270/john-machin)
#http://stackoverflow.com/questions/8733233/filtering-out-certain-bytes-in-python
def isValidXMLChar(char):
codepoint = ord(char)
return 0x20 <= codepoint <= 0xD7FF or \
codepoint in (0x9, 0xA, 0xD) or \
0xE000 <= codepoint <= 0xFFFD or \
0x10000 <= codepoint <= 0x10FFFF
def filterInvalidXMLChars(input):
return filter(isValidXMLChar, input)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.