Alternatives to XML?
Frank Millman
frank at chagford.com
Fri Aug 26 11:23:10 EDT 2016
"Joonas Liik" wrote in message
news:CAB1GNpTP0GD4s4kx07r1ujRNuXtOij4vF5uNYE1cFr_Y0xvi1g at mail.gmail.com...
> something like.. (untested)
def escape(untrusted_string):
''' Use on the user provided strings to render them inert for storage
escaping & ensures that the user cant type sth like '>' in
source and have it magically decode as '>'
'''
return untrusted_string.replace("&","&").replace("<",
"<").replace(">", ">")
def unescape(escaped_string):
'''Once the user string is retreived from storage use this
function to restore it to its original form'''
return escaped_string.replace("<","<").replace(">",
">").replace("&", "&")
> i should note tho that this example is very ad-hoc, i'm no xml expert just
> know a bit about xml entities. if you decide to go this route there are
> probably some much better tested functions out there to escape text for
> storage in xml documents.
Thanks very much, Joonas.
I understand now, and it seems to work fine.
As a bonus, I can now include '&' in my attributes in the future if the need
arises.
Much appreciated.
Frank
More information about the Python-list
mailing list