jmno has asked for the wisdom of the Perl Monks concerning the following question:
And the brief contents of alpha31.xmluse strict; use XML::Rules; use Text::CSV_XS; use FileHandle; my $csv = Text::CSV_XS->new({eol => "\n"}); my $parser = XML::Rules->new( rules => [ _default => 'content', Class => sub { $csv->print( $_[4]->{parameters}, [ map {$_[1]->{$_}} qw( Subject Course Title Descripti +on Prequisites Corequisites Requisites LectureHours LaboratoryHours C +reditHours Flags ) ]); return; } ] ); open my $FH, '>&STDOUT'; open my $File, 'alpha31.xml'; print $FH "Subject,Course,Title,Description,Prequisites,Corequisites,L +ectureHours,LaboratoryHours,CreditHours,Flags\n"; $parser->parse( $File, $FH);
It converts it to xml the way I want to, but it only does a single line and then complains about garbage after the </class> tag. Could anyone help me have this work on the entire file. I have posted 4 entries from the xml file which should print out 4 csv rows.<Class> <Subject>AAH</Subject> <Course>119</Course> <Title>History of World Architecture I</Title> <Description>Comprehensive background as well as concentration on indi +vidual cultures and their architects from ancient to modern times. Di +scussion of architectures from around the world. Specific details and + expressions of more generalized theories and strategies will be explo +red.</Description> <LectureHours>3</LectureHours> <LaboratoryHours>0</LaboratoryHours> <CreditHours>3</CreditHours> <LectureHours>3</LectureHours> <LaboratoryHours>0</LaboratoryHours> <CreditHours>3</CreditHours> <Flags>(H)(C)</Flags> </Class> <Class> <Subject>AAH</Subject> <Course>120</Course> <Title>History of World Architecture II</Title> <Description>Comprehensive background as well as concentration on indi +vidual cultures and their architects from ancient to modern times. Di +scussion of architectures from around the world.Specific details and expressions of more generalized theories and strategies will be explor +ed.</Description> <LectureHours>3</LectureHours> <LaboratoryHours>0</LaboratoryHours> <CreditHours>3</CreditHours> <LectureHours>3</LectureHours> <LaboratoryHours>0</LaboratoryHours> <CreditHours>3</CreditHours> <Flags>(H)(C) <Flags> </Class> <Class> <Subject>AAH</Subject> <Course>301</Course> <Title>Thinking About Art</Title> <Description>A course designed for those who find art pleasing, meanin +gful or significant and who want to extend the range of their sensibi +lities. Theories of art will be studied for insight, as well as for h + istorical interest and continuity. Works of art will be studied for th +eir intrinsic value, for their relation to ideas and events, and as c +ultural artifacts. Regular visits to area museums and galleries will be required.</Description> <Prerequisite>HUM 102, 104, or 106.</Prerequisite> <LectureHours>3</LectureHours> <LaboratoryHours>0</LaboratoryHours> <CreditHours>3</CreditHours> <Flags>(H)(C)</Flags> </Class> <Class> <Subject>AAH</Subject> <Course>322</Course> <Title>19th Century American Art and Culture</Title> <Description>This course explores the artistic history of the United S +tates, from an agrarian society that developed into an industrialized + nation with a distinguished national art. This broad chronological s + urvey begins with the colonial art of Copley, Peale, West and Stuart, +followed by the nation building iconography of the Hudson River Schoo +l. The art of Mount and Bingham reflect antebellum culture, followed by Johnson in post-Civil War America on the eve of the Gilded Age. Fin +ally, the course examines the realism of Homer and Eakins, defining a + truly American iconography.</Description> <Prerequisite>HUM 102, 104, or 106.</Prerequisite> <LectureHours>3</LectureHours> <LaboratoryHours>0</LaboratoryHours> <CreditHours>3</CreditHours> <Flags>(H)(C)</Flags> </Class>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: xml to csv
by Anonymous Monk on Nov 04, 2009 at 02:38 UTC | |
|
Re: xml to csv
by Jenda (Abbot) on Nov 04, 2009 at 14:19 UTC | |
by Anonymous Monk on Nov 04, 2009 at 14:43 UTC | |
|
Re: xml to csv
by llancet (Friar) on Nov 04, 2009 at 01:59 UTC | |
by Jenda (Abbot) on Nov 04, 2009 at 14:16 UTC |