#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper qw( Dumper );
use XML::Simple qw( );
$XML::Simple::PREFERRED_PARSER = 'XML::Parser';
my $latin1_xml = <<"__EOI__";
\311ric
__EOI__
my $utf8_xml = <<"__EOI__";
\303\211ric
__EOI__
my $xs = XML::Simple->new();
for my $xml ($latin1_xml, $utf8_xml) {
my $tree = $xs->XMLin($xml,
ForceArray => 1,
KeepRoot => 1,
);
local $Data::Dumper::Useqq = 1;
print Dumper $tree;
}
####
$VAR1 = {
'root' => [
"\x{c9}ric"
]
};
$VAR1 = {
'root' => [
"\x{c9}ric"
]
};
####
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper qw( Dumper );
use XML::Simple qw( );
my $tree = {
'root' => [
"\x{c9}ric"
]
};
$XML::Simple::PREFERRED_PARSER = 'XML::Parser';
my $xs = XML::Simple->new();
for my $enc (qw( iso-8859-1 UTF-8 )) {
my $xml = '';
{
open(my $fh, ">:encoding($enc)", \$xml) or die;
$xs->XMLout($tree,
XMLDecl => qq{},
KeepRoot => 1,
OutputFile => $fh,
);
close($fh);
}
local $Data::Dumper::Useqq = 1;
print Dumper $xml;
}
####
$VAR1 = "\n\311ric\n";
$VAR1 = "\n\303\211ric\n";