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:
my $p = new XML::Parser(
Style => 'Object',
ErrorContext => 2,
Sample code piece 2 (lifted from Merlyn's site):
my $count = 0;
my $fh = new IO::File("/home/graq/spreadsheet.xls");
my $p = HTML::Parser->new
xml_mode => 1,
my ($tagname, $attr) = @_;
push @state, $tagname;
## We are beginning state "@state"
}, "tagname, attr"],
my ($text) = @_;
## We see content within state "@state"
my ($tagname) = @_;
## We are ending state "@state"
Are you posting in the right place? Check out Where do I post X? to know for sure.
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
Want more info? How to link
or How to display code and escape characters
are good places to start.