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 :-)

In reply to Re: XML::Parser & encoding by grantm
in thread XML::Parser & encoding by Szani

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.