XML::Twig
has a simplify method which you can call on a XML element which according to docs says:
Return a data structure suspiciously similar to XML::Simple's
Here is an example:
use XML::Twig;
use Data::Dumper;
my $twig = XML::Twig->new(
twig_handlers => {
rec => \&rec,
}
)->parsefile( 'data.xml' );
sub rec {
my ($twig, $rec) = @_;
my $data = $rec->simplify;
say Dumper $data;
$rec->purge;
}
NB. The $rec->purge cleans out the record immediately from memory.
Running this against your XML example produces this:
$VAR1 = {
'f1' => 'v1',
'f2' => 'v2'
};
$VAR1 = {
'f1' => 'v1b',
'f2' => 'v2b'
};
$VAR1 = {
'f1' => 'v1c',
'f2' => 'v2c'
};
Which I hope is suspiciously like what comes out of XML::Simple :)
/I3az/