XML::Parser - trapping badly formed XML ?

H

Hooby

I have been using the wonderful XML::parser on a winXP box successfully for
a long time now. Unfortunately, I have several (hundred?) thousand XML files
that I process on a weekly basis. Every so often - say 1 in 10,000 might be
badly formed (but which one?). When XML::parser hits one of these it dies
(just as the documentation says it would). BTW - I have no control over the
badly formed XML if it occurs - I just have deal with what I am given...

Is there a way to trap or change this behaviour so that I can pass over the
offending file gracefully and let the program continue with the others (it
takes several hours to complete - amd I don't mind missing one file
occasionally). In other words can I trap the error in perl to make it a warn
not a die?

Any suggestions gratefully received!

Thanks Andy

Typical usage as seen below :

use XML::parser;
$parser = new XML::parser(Style=>'Subs', Pkg=>'SubHandlers', ErrorContext =>
2);
$parser->setHandlers( Start => \&startElement,
End => \&endElement,
Char => \&characterData
);
$currentfile = $filename;
$parser->parsefile($currentfile); # open up and parse the classification
scheme to find out what filelists were created and generate indexes as it
goes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top