XML::Parser - trapping badly formed XML ?

Discussion in 'Perl Misc' started by Hooby, Jul 27, 2005.

  1. Hooby

    Hooby Guest

    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
    Hooby, Jul 27, 2005
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eric
    Replies:
    1
    Views:
    5,026
    Karl Seguin
    Nov 17, 2005
  2. Gil
    Replies:
    1
    Views:
    2,731
    morice
    Dec 24, 2003
  3. Seeker
    Replies:
    8
    Views:
    1,865
    Vladimir S. Oka
    Mar 24, 2006
  4. Replies:
    0
    Views:
    573
  5. Replies:
    27
    Views:
    369
    Peter J. Holzer
    May 18, 2007
Loading...

Share This Page