I am editing some XML files using XML::Twig
below are the code :
my $twig = XML::Twig->new(
pretty_print => 'indented',
twig_handlers => {
Vendor => sub {
$_->set_att( 'ID' => $_->{'att'}->{'att1'} );
$_->set_att( 'ID' => $_->{'att'}->{'att2'} );
$_->set_att( 'ID' => $_->{'att'}->{'att3'} );
$_->set_att( 'ID' => $_->{'att'}->{'att4'} );
},
},
);
$twig->parsefile('myfile');
$twig->flush;
The problem is that this code does not save the xml attributes in the same order in the edited file.
for example this line from the input xml :
<DEVICE OVERWRITE="TRUE" STRING="TRUE" BLOCK="FALSE">
is replaced by this line in the output xml :
<DEVICE BLOCK="FALSE" STRING="TRUE" OVERWRITE="TRUE">
How can I save the attributes in the same order as the original file so that if I compare the two files with a revision system, I only see the changes that I made?