MartinSchneider has asked for the wisdom of the Perl Monks concerning the following question:
But the document needs to be dynamic, so I tried foreach loops like this:use strict; use XML::Generator; open (RPT, ">menu.xml"); my $gen = XML::Generator->new( 'escape' => 'always', 'pretty' => 2); my $xml = $gen->Menu( $gen->Course("Appetizers"), $gen->Items( $gen->Name("Soup"), $gen->Name("Salad") ), $gen->Course("Entres"), $gen->Items( $gen->Name("Oysters"), $gen->Name("Pizza") ) ); print RPT "$xml";
But this fails at the 1st foreach. I've searhed several places, but have not yet found a solution. Is a loop like this possible? Am I taking the wrong approach? Thank you, Martinuse strict; use XML::Generator; open (NEWRPT, ">newmenu.xml"); my %myhash = ( "Appetizers" => ["Soup", "Salad"], "Entres" => ["Oysters", "Pizza"] ); my $newgen = XML::Generator->new( 'escape' => 'always', 'pretty' => 2); my $newxml = $newgen->Menu( foreach my $course (keys %myhash) { $newgen->Course("$course"), $newgen->Items( my @items = @{$myhash{$course}}; foreach my $item (@items) { $newgen->Name("$item") }) }); print NEWRPT "$newxml";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XML::Generator loop
by theguvnor (Chaplain) on Nov 06, 2001 at 05:29 UTC | |
by MartinSchneider (Initiate) on Nov 06, 2001 at 06:06 UTC | |
|
Re: XML::Generator loop
by impossiblerobot (Deacon) on Nov 06, 2001 at 04:32 UTC | |
by MartinSchneider (Initiate) on Nov 06, 2001 at 06:02 UTC |