#!/usr/bin/perl use Data::Dumper; use XML::Simple; if (scalar(@ARGV)<1) { print STDERR "Syntax: testit.pl inputfile.ofx [...]\n\n"; exit(1); } for my $xmlfile (@ARGV) { my $txtfile = $xmlfile; unless ($txtfile =~ s/\.[Oo][Ff][Xx]$/.txt/) { $txtfile = $xmlfile . ".txt"; } print STDERR "Converting $xmlfile --> $txtfile\n\n"; open XMLFILE, "<", $xmlfile or die $!; open TXTFILE, ">", $txtfile or die $!; my $thexml; while() { if (m//) { $thexml = $_; last;} } while() { $thexml .= $_; } my $xml = new XML::Simple; my $thedata = $xml->XMLin($thexml); my $thelist = $$thedata{BANKMSGSRSV1}{STMTTRNRS}{STMTRS}{BANKTRANLIST}{STMTTRN}; #print $#$thelist; foreach $i (@$thelist) { #print Dumper($i); my $thedate = $$i{DTPOSTED}; my ($year, $month, $day) = $thedate =~ /([0-9]{4})([0-9]{2})([0-9]{2})/; print TXTFILE "$day/$month/$year\t" . $$i{TRNTYPE} . "\t" . $$i{TRNAMT} . "\t" . $$i{MEMO} . "\n"; } close TXTFILE; close XMLFILE; } # Loop round to the next file!