Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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;

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

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

  • 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> <u> <ul>
  • 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 intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2023-09-23 11:39 GMT
Find Nodes?
    Voting Booth?

    No recent polls found