in reply to Twig Question: Create a new XML doc using twig?

You are creating, and printing, an element. If you want the XML declaration to be output, you can only do this on a complete twig. And of course you need to set the declaration for that twig, as it is optional.

So replace your last 2 statements by the following code:

my $twig= XML::Twig->new(); $twig->set_xml_version( '1.0'); $twig->set_root( $root); $twig->print;

You can, of course, add option to new, like pretty_print => 'indented' for example.