XML::Filter::Sort is a SAX filter for sorting elements in XML.
use XML::SAX::Machines qw( :all );
my $sorter = XML::Filter::Sort->new(
Record => 'person',
Keys => [
[ 'lastname', 'alpha', 'asc' ],
[ 'firstname', 'alpha', 'asc' ],
[ '@age', 'num', 'desc']
my $filter = Pipeline( $sorter => *STDOUT );
Or from the command line:
This module is a SAX filter for sorting 'records' in XML documents (including documents larger than available memory). The xmlsort utility which is included with this distribution can be used to sort an XML file from the command line without writing Perl code (see perldoc xmlsort).