Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: XML help

by pjotrik (Friar)
on Aug 06, 2008 at 11:35 UTC ( [id://702606]=note: print w/replies, xml ) Need Help??


in reply to XML help

Quick and dirty? Keep arrayrefs in the Outcond array. UNTESTED changes to the code:
... my @Outcond = ([]); #array for out conditions ... sub Outcond { my( $twig, $s )= @_; push(@{$Outcond[$#Outcond]},( $s->att('NAME'))); } ... sub Output { my( $twig, $s )= @_; push(@Jobs,( $s->att('JOBNAME'))); push(@Time,($s->att('TIMEFROM'))); push(@Desc,($s->att('DESCRIPTION'))); push(@Days,($s->att('DAYS'))); push(@Outcond, []); #At the end you will have a trailing empty arr +ayref at the end of @Outcond, but you don't need to worry about that +given the way you print your output } ... sub write_text { my $worksheet = shift; ... #loop all data and output in correct positions while ($count <= (scalar(@Jobs))) { $worksheet->write($ygroup, $xgroup, $group[$count-1]); $worksheet->write($yjobs++, $xjobs, $Jobs[$count-1]); $worksheet->write($yDays++, $xDays, $Days[$count-1]); $worksheet->write($yTags++, $xTags, $Tag[$count-1]); $worksheet->write($yStarting++, $xStarting, $Time[$count-1]); $worksheet->write($yDesc++, $xDesc, $Desc[$count-1]); $worksheet->write($yOut++, $xOut, join(',', @{$Outcond[$count- +1]}); $worksheet->write($yIn++, $xIn, $Incond[$count-1]); $ygroup = ($ygroup+$yjobs); $count++; } }
But generally, it would be better to store corresponding data (i.e. data belonging to every JOB element) together in one structure (or object). Having the data in 8 distinct arrays really hurts the eye. And it's not only non-elegant, you may easily get into problems when a child element is missing - that would mix up your arrays.

Also, XML::Twig is excellent in processing XML documents as they come. You might output your record to excel every time the whole job element has been parsed (i.e. in the Output sub). If you want to store all the data, another XML library may be better, personally, I'd choose XML::Simple.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://702606]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-03-29 15:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found