in reply to XML encoding problem

The problem comes from LibXML, wich works with utf8 only. Generally if you want to work with XML, you'd better stick to utf8 encoding. You don't need to rewrite all of your templates though; simply add something like this :
use Unicode::String; Unicode::String->stringify_as('utf8'); $text = Unicode::String::latin1($text);
to convert dynamically your iso-8859-1/15 strings to utf8.

Replies are listed 'Best First'.
Re^2: XML encoding problem
by boboson (Monk) on Mar 15, 2006 at 09:34 UTC
    I am not sure what I will do, but this gave me something to work with.
    I created a small sub that converts the XML string to latin1 (which is the same as iso-8859-1??? or...)
    use Unicode::String qw(utf8 latin1); sub utf8_to_latin1 { # get arguments my ($s1) = @_; # create a utf8 string with initial value of s1 # strange! it should already be in utf8 my $utf8 = Unicode::String->new( $s1 ); # convert to latin1 my $s2 = Unicode::String::latin1($utf8); return $s2; }
    but I don't understand why I have to create a new utf8 string, when the XML string should already be in utf8?

      You're simply creating an object, you don't actually need it to pass the string to it. Use Unicode::String->stringify_as('latin1'); instead, see Unicode::String documentation :

      $us = Unicode::String->new( $initial_value )
      (...)
      In general it is recommended to import and use one of the encoding specific constructor functions instead of invoking this method.