#!/bin/perl -w
 use strict;
 use XML::Parser;
 use Unicode::String;

 my $p= new XML::Parser( Handlers =>
                  { Start   => \&default_latin1,
                    End     => \&default_latin1,
                    XMLDecl => sub { decl( "ISO-8859-1",@_); },
                    Default => \&default_latin1
                          },
                       );
 $p->parsefile($ARGV[0]);
 exit;

 sub decl
   { my( $new_encoding, $p, $version, $encoding, $standalone)=@_;
     print "<?xml version=\"$version\" encoding=\"$new_encoding\"";
     print "standalone=\"$standalone\"" if( $standalone);
     print "?>\n";
   }

 sub default_latin1                          
   { my $p= shift;
     my $string= $p->recognized_string();   # get the UTF8 string
     my $u= Unicode::String::utf8( $string);# create Unicode::String 
     print $u->latin1;                      # convert string to latin1
   }
