I am trying to generate xml data that will be read by some flash applications and it has to be in a specific format. Here is a sample of what the output should look like.
<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>
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.
my %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 run this code, it prints output like this
<chart caption="Chart Title"
xAxisName="xAxis"
yAxisName="yAxis"
subcaption="Subtitle" /><chart>
<set>
<label>January</label>
<value>10622</value>
</set>
..
...
</chart>
If I try and put a foreach loop inside the creation of the XML, it gives me syntax errors
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]);
});
Any ideas on how to proceed? Thanks!