I am creating a new XML document from scratch using XML::Twig. The root element should have a prefix and a namespace declaration. All children should also belong to this namespace and use this prefix.
The output should be something like this:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<abc:root xmlns:abc="http://www.somehost.com/abc-data/ns/5.0.0" version="5.0.0.0">
<abc:element name="myElement">
This is my element
</abc:element>
</abc:root>
I suppose it would look somewhat like this:
my $new_twig = XML::Twig->new(map_xmlns => {'http://www.somehost.com/abc-data/ns/5.0.0' => "abc"}, pretty_print => 'indented');
my $root = XML::Twig::Elt->new('root');
$new_twig->set_encoding('UTF-8');
$new_twig->set_standalone("no");
$new_twig->set_root( $root);
my $element = XML::Twig::Elt->new('element' => {'name'=>'myElement};
$element->set_text('This is my element');
$element->paste(last_child=>$root);
# print in a file
open (TMP, "> $new_file_name");
select TMP;
$new_twig->print(\*TMP);
close TMP;
This may seem simple, but I'm still a newby to Perl and this is giving me a hard time! Thanks for your help!!!