in reply to Re: Outputting a hash as XML
in thread Outputting a hash as XML

I found the create_element function really useful, have added a slight modification to the above function to handle keys that are in turn array references
sub create_element { my $gi = shift; my $data = shift; my $node = XML::Twig::Elt->new($gi); if (ref $data eq "HASH") { while (my ($key, $value) = each(%$data)) { if (ref $value eq "ARRAY") { for my $i (@$value) { createXmlTree($key, $i)->paste(last_child => $node); } } else { createXmlTree($key, $value)->paste(last_child => $node); } } } else { $node->set_text($data); } $node; };
Thanks Joseph