XML::Smart:
use strict ;
use warnings ;
use XML::Smart ;
my %hash = (
'key1' => 'value1' ,
'key2' => 'value2' ,
'key3' => 'value3' ,
'key4' => 'value4' ,
);
my $xml_obj = new XML::Smart();
foreach my $key ( keys %hash ) {
$xml_obj->{form}{$key} = { CONTENT => $hash{ $key } } ;
}
print $xml_obj->data();
Output
<?xml version="1.0" encoding="iso-8859-1" ?>
<?meta name="GENERATOR" content="XML::Smart/1.74 Perl/5.010001 [linux]
+" ?>
<form>
<key2>value2</key2>
<key4>value4</key4>
<key1>value1</key1>
<key3>value3</key3>
</form>