[Canberra-pm] Parsing an XML document using XML::Twig and using it on an Template [SEC=UNCLASSIFIED]

John.Hockaday at ga.gov.au John.Hockaday at ga.gov.au
Wed Mar 17 18:56:58 PDT 2010


Hi All,

I am trying to read an XML document into a hash handler that can be used on the Template package.  I thought that XML::Twig would be good for this but I have no idea how to create a hash/array "thingy" that can be passed to the Template module. Can someone help with this?  I don't understand the hash/array structure created by the XML::Twig and for the input to the Template.

Here is some idea of the code:

 use XML::Twig;
 use Template;

 my ($inputFile) = 'bob.xml';
 my ($templatePath) = '/public/asddadm/test';
 my ($templateFile) = 'temp.xml';
 my ($output) = 'output.xml';

 my $twig= new XML::Twig;
 $twig->parsefile( $inputFile);    # build the twig
 my $root = $twig->root;
 $root->print => 'indented',                # output will be nicely form

 my $temp = Template->new({'INCLUDE_PATH' => "$templatePath",
                        'TAG_STYLE' => 'html',
                        'PRE_CHOMP' => '1',
                        'ABSOLUTE' => '1',})
        || die $Template::ERROR, "\n";

        # process the template object
 no strict "refs";
 $temp->process($templateFile, $root, $output)
        || die $temp->error();

 exit (0);

Thanks.


John


More information about the Canberra-pm mailing list