As mentionned in the docs XML::Parser converts all the text it parses to UTF-8. You have several solutions to get the original encoding back: use the $p->original_string() method to get the text, or convert the UTF-8 back to ISO-8859-1 (BTW, are you sure you want to use this encoding? If you are dealing with scandinavian text you might need ISO-8859-4 to get all the characters you need). If your system has the iconv library (*nix or MS-Windows with cygwin) then you can use the Text::Iconv module.

<plug type="shameless">You can also use XML::Twig in keep_encoding mode or with an input filter to get the dat in the required encoding:

#!/bin/perl -w use strict; use XML::Twig; my $t = new XML::Twig(input_filter => 'latin1'); $t->parse( \*DATA); print "content: ", $t->root->text, "\n"; __DATA__ <?xml version="1.0" encoding="ISO-8859-1"?> <doc>Humörsvängningar</doc>

</plug>

BTW, try not to use module names as the title of a node, as this might interfere with the review of the module, try "XML::Parser encoding problem" for example.


In reply to Re: XML Parser by mirod
in thread XML Parser encoding problem (was: XML::Parser) by mahesh2812

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.