graq has asked for the wisdom of the Perl Monks concerning the following question:

I am having problems parsing an 'XML' file.

Microsoft is moving it's Office software over to using XML, so they are now producing "Microsoft Excel XML spreadsheets" - and this is what I have to work on.

I have tried XML::Parser but it bombs out horribly. I have double checked the file, getting a colleague to download it onto the local server, but it still appears full of 'padding' at the end of the file. The error is:  not well-formed (invalid token) at line 1, column 181703, byte 181705 at PATH/XML/ line 187

I toyed with merlyn's idea of using HTML::Parser, but the XML structure is too flat - the state just always being "Workbook Worksheet Table Row Cell Data", so I unable to identify the data.

Does anyone know of any other tools, or have any ideas on how to deal with this? Getting rid of the 'padding' seems tricky to me as it's a load of gibberish - but so is Microsoft's 'XML'.

(Apologies for not being able to supply the data - the only file I have is company sensitive)

Sample code piece 1:

use Data::Dumper; use XML::Parser; my $p = new XML::Parser( Style => 'Object', ErrorContext => 2, ); $p->parsefile('Spreadsheet.xls');

Sample code piece 2 (lifted from Merlyn's site):

use IO::File; use Data::Dumper; use HTML::Parser; my $count = 0; my $fh = new IO::File("/home/graq/spreadsheet.xls"); my @state; my $p = HTML::Parser->new ( xml_mode => 1, start_h => [sub { my ($tagname, $attr) = @_; push @state, $tagname; ## We are beginning state "@state" print '::'."@state".'::'."\n"; }, "tagname, attr"], text_h => [sub { my ($text) = @_; ## We see content within state "@state" }, "dtext"], end_h => [sub { my ($tagname) = @_; ## We are ending state "@state" pop @state; }, "tagname"], ); $p->parse_file($fh); $p->eof;