, XML::Simple . , ; , , . , , "", .
, . , . , , .
. , .
, , . , XML:: Simple - : OO sorted_keys. :
use strict;
use warnings;
use XML::Simple;
use Data::Dumper;
package MyXMLSimple;
use base 'XML::Simple';
sub sorted_keys
{
my ($self, $name, $hashref) = @_;
if ($name eq 'supertag')
{
return ('tag1', 'tag3','tag4','tag10');
}
return $self->SUPER::sorted_keys($name, $hashref);
}
package main;
my $xmlParser = MyXMLSimple->new(
KeepRoot => 1,
ForceContent => 1,
);
my $structure = {
supertag => {
tag1 => { content => 'value 1' },
tag10 => { content => 'value 2' },
tag3 => { content => 'value 3' },
tag4 => { content => 'value 4' },
},
};
my $xml = $xmlParser->XMLout($structure);
print "The xml generated is:\n$xml\n";
print "The read in structure then is:\n" . $xmlParser->XMLin($xml) . "\n";
:
The xml generated is:
<supertag>
<tag1>value 1</tag1>
<tag3>value 3</tag3>
<tag4>value 4</tag4>
<tag10>value 2</tag10>
</supertag>
The read in structure then is:
$VAR1 = {
'supertag' => {
'tag10' => {
'content' => 'value 2'
},
'tag3' => {
'content' => 'value 3'
},
'tag1' => {
'content' => 'value 1'
},
'tag4' => {
'content' => 'value 4'
}
}
};
XML::Simple CPAN.