NAME

XML::Simple::Sorted - Version of XML::Simple with enforced tag and attribute sort order. This module was born out of the need to interface with some legacy systems that could not be changed and that expected a certain tag order, otherwise they would crash and burn... just kidding ;-)

SYNOPSIS

use XML::Simple::Sorted;

my $xml = XML::Simple::Sorted->new( [OPT] ) ;

CLASS METHODS

new()

Creates a new instance of XML::Simple::Sorted. Here, we simply override the constructor of XML::Simple and check if the user has given an *.ini file or hash containing the desired tag and attribute order.

SortOrder

This new option can either specify a hashref containing the desired tag and attribute sort order or the path to an ini file (see Config::IniFiles) containing the desired tag and attribute sort order. This method will croak() if one specifies a non-existing config file.

Example

my $xml = XML::Simple::Sorted->new(SortOrder => 'sort_config.ini');

my $sort_hashref = { ... };
my $xml = XML::Simple::Sorted->new(SortOrder => $sort_hashref);

Example sort_config.ini file

[message]
    tags = [ 'tradeid', 'leg' ]
    attr = [ 'system', 'sender', 'receiver', 'timestamp' ]
[leg]
    tags = [ 'legid', 'payment', 'book', 'product' ]
[payment]
    tags = [ 'start', 'end', 'nominal', 'currency' ]
...

Example sort_hashref

my $order = {
    message => {
        tags => [ 'tradeid', 'leg' ],
        attr => [ 'system', 'sender', 'receiver', 'timestamp' ]
    },
    leg => {
        tags => [ 'legid', 'payment', 'book', 'product' ]
    },
    payment => {
        tags => [ 'start', 'end', 'nominal', 'currency' ]
    },
};
Please note that the 'tags' und 'attr' parameters are semantically identical, i.e. one
could specify the attribute order also using the 'tags' parameter and vice versa.
Two parameters only serve to hopefully improve the readability of the *.ini file / hashref.

sorted_keys()

Override method sorted_keys() of XML::Simple to perform the desired ordering of XML tags and attributes.

SEE ALSO

XML::Simple, Config::IniFiles

AUTHOR

Sinisa Susnjar <sini@cpan.org>

COPYRIGHT AND LICENSE

Copyright 2012 Sinisa Susnjar

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.