Emanuel has asked for the wisdom of the Perl Monks concerning the following question:
Hello wise monks
I'm running into a problem, and I can't seem to find any solution to it for the past 2 days. Here's what it's all about:
o I got an UTF-8 encoded XML file
o I parse it in and want to write some parts of it to a mysql database, ISO-8859-1 encoded
Everything is working fine, i'm reading the XML in, creating a hash out if it with XML::Parser, data gets written to MySQL aswell, but when I check the data in the table, it's UTF-8 again.
So I started playing with Text::Iconv, and came to this:
When I print the values out (eg: print $converter->convert($value)."\n"; ) it looks correct (eg ISO-8859-1 encoded), but when writing to the DB, it's UTF-8 again (meaning all special chars, like öäüéàè etc are some weird chars like Ã| etc...).
I'm really going nuts here, and would appreciate any help provided for this.
If more of the source is needed just tell me.
Thanks in Advance
Emanuel
I'm running into a problem, and I can't seem to find any solution to it for the past 2 days. Here's what it's all about:
o I got an UTF-8 encoded XML file
o I parse it in and want to write some parts of it to a mysql database, ISO-8859-1 encoded
Everything is working fine, i'm reading the XML in, creating a hash out if it with XML::Parser, data gets written to MySQL aswell, but when I check the data in the table, it's UTF-8 again.
So I started playing with Text::Iconv, and came to this:
--- some stuff above --- $parser->parsefile(shift @ARGV, ProtocolEncoding => "ISO-8859-1"); --- some stuff inbetween --- my $converter = Text::Iconv->new("UTF-8","ISO-8859-1"); while (my($key,$value)=each(%attrs)) { push (@value_stack, { $key=>$value }); if ($program_hash{$current_filmid}{$key} eq '') { $program_hash{$current_filmid}{$key} = $conver +ter->convert($value); } else { if ($key ne "EventId" && $key ne "KanalId") { $program_hash{$current_filmid}{"$key.$ +value"} = $converter->convert($value); } } } --- some stuff below ----
When I print the values out (eg: print $converter->convert($value)."\n"; ) it looks correct (eg ISO-8859-1 encoded), but when writing to the DB, it's UTF-8 again (meaning all special chars, like öäüéàè etc are some weird chars like Ã| etc...).
I'm really going nuts here, and would appreciate any help provided for this.
If more of the source is needed just tell me.
Thanks in Advance
Emanuel
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: XML::Parser Encoding (UTF-8 -> ISO-8859-1)
by grantm (Parson) on Sep 12, 2002 at 02:13 UTC | |
by Emanuel (Pilgrim) on Sep 12, 2002 at 02:32 UTC | |
Re: XML::Parser Encoding (UTF-8 -> ISO-8859-1)
by jkahn (Friar) on Sep 12, 2002 at 00:49 UTC | |
by Emanuel (Pilgrim) on Sep 12, 2002 at 01:28 UTC | |
Re: XML::Parser Encoding (UTF-8 -> ISO-8859-1)
by ash (Monk) on Sep 12, 2002 at 09:20 UTC | |
Re: XML::Parser Encoding (UTF-8 -> ISO-8859-1)
by bart (Canon) on Sep 12, 2002 at 20:15 UTC | |
Re: XML::Parser Encoding (UTF-8 -> ISO-8859-1)
by Stegalex (Chaplain) on Sep 14, 2002 at 12:26 UTC |
Back to
Seekers of Perl Wisdom