in reply to
XML Twig sprint output not preserving > entity
You need to set keep_encoding.
#!/usr/bin/perl --
use strict;
use warnings;
use XML::Twig;
use Data::Dump qw' dd ';
Main( @ARGV );
exit (0);
sub Main {
my %files;
my $filename;
my $subprint = sub {
my( $twig, $_ ) = @_;
push @{ $files{ $filename }}, $_->sprint;
return;
};
my $twig = XML::Twig->new(
ignore_elts => { brief => 'discard', detailed => 'discard' },
keep_encoding => 1,
pretty_print => 'indented',
TwigHandlers => {
'myroot/classes' => $subprint,
},
);
for my $file( @_ ) {
$filename = $file;
eval {
$twig->parsefile( $file );
1;
} or warn "ERROR parsefile($file): $@ ";
$twig->purge;
}
dd \%files;
}