in reply to XML::Parser & encoding

  1. There are very, very few legitimate reasons to use the ProtocolEncoding option with XML::Parser. If you think you need to do it because the XML document does not declare an encoding then the right solution is to fix the XML document - because if it doesn't use UTF-8 or UTF-16 and it doesn't declare an encoding then it's not XML.
  2. You should almost never use a text string* in Perl that's not either plain 7bit ASCII or UTF-8. Perl's built-in functions such as index(), length(), reverse() etc 'understand' ASCII and UTF-8, they don't understand other encodings.
  3. Given that you have successfully converted a non-UTF document to UTF-8 on input, the only other place you would typically need to do an encoding conversion is on output. For example (from the Perl XML FAQ):
    open my $fh, '>:encoding(windows-1250)', $path or die "open($path): $! +"; print $fh $utf_string;
* My definition of 'text string' here excludes strings of binary bytes - which are of course perfectly acceptable in Perl but not usually encountered in XML :-)