|Perl Monk, Perl Meditation|
Cleaning up non 7-bit Ascii Chars for XML-processingby liverpole (Monsignor)
|on Nov 11, 2010 at 18:47 UTC||Need Help??|
liverpole has asked for the
wisdom of the Perl Monks concerning the following question:
Greeting fellow monks,
For the better part of this past year, I've been the principal engineer at my company on a project involving handling XML data. I chose to use XML::Simple (with XML::LibXML::SAX for the parser), and it has served my needs quite well, even though it was my first real experience with XML processing.
Along the way, I've needed to massage input text so that XML::Simple would handle it correctly. The XML is always output as "UTF-8", and the subroutine I was using for "cleaning" the input text looked like this:
Yesterday we discovered that this wasn't sufficient; an error occurred because someone gave us input containing a character which looked like an apostrophe (ascii 0x27), but was in fact an ascii 0x92 ("smart quotes", or whatever they're called), which broke the parsing. When I say "broke the parsing", I mean that I this error from XMLin:
So I revised my subroutine as follows:
That is, it will handle those "smart quotes" by converting them to "\", as well as any other ascii characters with the high bit turned on.
My questions are:
Thanks in advance for any enlightenment!