#!/perl/bin/perl -w use strict; use XML::Twig; my $field= 'last_ds'; my $twig= new XML::Twig; $twig->parsefile( "RoamAboutAP_192.168.25.88.xml"); my $root= $twig->root; my @ds= $root->children; my @sorted= sort { $b->first_child( $field)->text <=> $a->first_child( $field)->text } @ds; open (XML, ">>test.xml") || warn; foreach my $attr (@ds) { my $g = $attr->first_child( 'min')->text; my $blk= $attr->first_child( 'max')->text; my $blg= sprintf( "TEST"); my $eblg= new XML::Twig::Elt( 'Average', $blg); $eblg->paste( 'last_child', $attr); } $twig->set_pretty_print('indented'); $twig->print; close XML;