Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: xml to csv

by Anonymous Monk
on Nov 04, 2009 at 14:43 UTC ( [id://804937]=note: print w/replies, xml ) Need Help??


in reply to Re: xml to csv
in thread xml to csv

#!/usr/bin/perl -- use warnings; use strict; use XML::Rules; use Text::CSV_XS; Main(@ARGV); exit(0); sub Main { use autodie; open my $File, shift || 'alpha31.xml'; RuleCvs( $File, \*STDOUT ); #~ use FileHandle; #~ RuleCvs( FileHandle->new(shift // 'alpha31.xml'), \*STDOUT ); use + 5.10.0; #~ RuleCvs( FileHandle->new(shift || 'alpha31.xml'), \*STDOUT ); #~ RuleCvs( FileHandle->new(shift), \*STDOUT ); } ## end sub Main BEGIN { my (@Heads) = qw( Subject Course Title Description Prequisites Corequisites Requisites LectureHours LaboratoryHours CreditHours Flags ); sub RuleCvs { my ( $InFh, $OutFh ) = @_; my $csv = Text::CSV_XS->new( { eol => "\n" } ); my $parser = XML::Rules->new( rules => [ _default => 'content', Class => sub { $csv->print( $_[4]->{parameters}, [ @{ $_[1] }{@Heads} ] ); return; } ] ); print $OutFh join( ',', @Heads ), "\n"; $parser->parse( $InFh, $OutFh ); return; } ## end sub RuleCvs } ## end BEGIN __END__

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-23 20:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found