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/Parser.pm 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;

In reply to Problems with Microsft's new Office 'XML' by graq

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.