hallikpapa has asked for the wisdom of the Perl Monks concerning the following question:
I have been able to successfully get some XML generated. For instance I can do the first line properly, but the problem comes with the loop. It's either I cannot get the syntax right, or it prints the output incorrectly.<chart caption='Monthly Sales Summary' subcaption='For the year 2006' +xAxisName='Month' yAxisName='Sales' numberPrefix='$'> <set label='January' value='17400' /> <set label='February' value='19800' /> <set label='March' value='21800' /> <set label='April' value='23800' /> <set label='May' value='29600' /> <set label='June' value='27600' /> <set label='July' value='31800' /> <set label='August' value='39700' /> <set label='September' value='37800' /> <set label='October' value='21900' /> <set label='November' value='32900' /> <set label='December' value='39800' /> </chart>
If run this code, it prints output like thismy %xml_hash; print $xml->chart({caption => 'Chart Title', subcaption => 'Subtit +le', xAxisName => 'xAxis', yAxisName => 'yAxis'}); while ( my $row = $sp->fetchrow_hashref ) { push @{ $xml_hash{set} }, $row; } my $xmlOut = XMLout(\%xml_hash, NoAttr => 1, RootName => 'chart'); print $xmlOut;
If I try and put a foreach loop inside the creation of the XML, it gives me syntax errors<chart caption="Chart Title" xAxisName="xAxis" yAxisName="yAxis" subcaption="Subtitle" /><chart> <set> <label>January</label> <value>10622</value> </set> .. ... </chart>
Any ideas on how to proceed? Thanks!print $xml->chart({caption => 'Chart Title', subcaption => 'Subtitle', + xAxisName => 'xAxis', yAxisName => 'yAxis'}, foreach my $key ( sort keys %hash) { my ( $date, $cust ) = split( /:/, $key ); $xml->data({set => },['set'], $hash{$key}[2]); });
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XML::Generator loop
by GrandFather (Saint) on Mar 31, 2008 at 00:41 UTC | |
|
Re: XML::Generator loop
by pc88mxer (Vicar) on Mar 31, 2008 at 00:46 UTC | |
|
Re: XML::Generator loop
by Cody Pendant (Prior) on Mar 31, 2008 at 02:51 UTC | |
|
Re: XML::Generator loop
by Jenda (Abbot) on Mar 31, 2008 at 17:45 UTC |