[XML-SIG] processing "special characters" efficiently
Goodger, David
dgoodger@atsautomation.com
Fri, 7 Apr 2000 16:08:39 -0400
> From: Craig.Curtin@wdr.com
> Date: Thu, 6 Apr 2000 15:57:43 -0500
>
> i'm looking for an efficient mechanism for filtering out
> XML special characters....
>
> the following code executes in slo-mo, can anyone =20
> identify a more efficient way? this is obviously not
> optimal. any help is appreciated.
>
> thanks,
>
> craig
>
> text2XMLSpecialCharacters=3D{ '&': '&', =20
> '<': '<', =20
> '>': '>', =20
> }
>
> for k in text2XMLspecialChars.keys():
> data =3D string.replace(data, k, text2XMLspecialChars[k])
This code has a dangerous logic bug. You cannot depend on the order of
dictionary keys; if '&' happened to come up last, then the input data =
"<you> & <me>" would produce the following output:
&lt;you&gt; & &lt;me&gt;
Which is probably not what you want. (I won't mention the variable name
problems.)
David Goodger
Systems Administrator, Advanced Systems
Automation Tooling Systems Inc., Automation Systems Division
direct: (519) 653-4483 ext. 2126 fax: (519) 653-8948
e-mail: dgoodger@atsautomation.com
This message contains NO confidential information and is intended
for anybody who is interested. Even if you are not the named addressee you
may disseminate, distribute or copy this e-mail. Do whatever you like with
it on your system, I don't care.