I am trying to get my hands around XML::Twig(like learning a whole new application) and I am having problems getting it to print to a filehandle. I only want to print the data that I have pulled not the whole document and eventually I want this to be a different HTML file. Here is a sample of what I am trying to do:
My XML File:
<script type="ApplicationPerspective" version="5.3.13.179" recorder="8
+.6.59.276" sav="25" guid="296A95D0-E8B6-4989-AA21-126796A3AD3F" xmlns
+="http://www.keynote.com/namespaces/tstp/script">
<name>
<![CDATA[GT Amadeus]]>
</name>
<actions>
<action FrameErrorFatal="1" MetaErrorFatal="1">
<name>
<![CDATA[Home Page]]>
</name>
<description>
<![CDATA[]]>
</description>
</action>
</actions>
</script>
use strict;
use warnings;
use XML::Twig;
my $file = $ARGV[0];
my $output = "/home/todd/Scripts/output.txt";
open( OUT, ">$output") or die "can't open file: $!";
my $twig = new XML::Twig(
twig_handlers => { name => \&name }
);
$twig->parsefile($file);
sub name {
my ($twig, $name) = @_;
my $stuff = $name->text();
$stuff->print( \*OUT);
# print "$stuff\n";
$twig->purge;
}
close(OUT);
What the is the best method to do this? In the XML::Twig docs it only has an example of using a filehandle with twig_print_outside_roots.
Thanks in advance,
Todd