I'm trying to parse an XML doc with XML::Twig XML::Simple*, which apparently is calling XML::SAX::PurePerl under the hood. At some point in the 18 MB XML file the parser chokes and throws an exception:

Invalid quote token [Ln: 1, Col: 14]

The problem is, I don't know what line in the file caused the error. I found the method that generates that output (I think) in XML::SAX::PurePerl and tried to redefine it to print the input data. I added the following code to the bottom of my script:

{ package XML::SAX::PurePerl; sub quote { my ($self, $reader) = @_; my $data = $reader->data; # Original # $data =~ /^(['"])/ or $self->parser_error("Invalid quote tok +en", $reader); # Modified $data =~ /^(['"])/ or do { $data =~ /^(.)/; my $quote_char = $1; warn "Invalid quote token found: -->$quote_char<--\n" . "Source line follows:\n" . $data; $self->parser_error("Invalid quote token", $reader); }; $reader->move_along(1); return $1; } }

Now, however, instead of displaying the warning message when the system hits the mystery line, I get a different error:

Can't locate object method "new" via package "XML::SAX::PurePerl" at C +:/Perl_5.8.8/site/lib/XML/SAX/ ParserFactory.pm line 43.

I thought I was using package appropriately, but I obviously changed more than I expected. I'm a bit rusty (haven't had much time to code lately) and I think I'm missing a fundamental concept. Whack away with the clue-stick, please.

Thanks

*Updated after additional debugging, per Re^2: Redefining a method in XML::SAX::PurePerl.


In reply to Redefining a method in XML::SAX::PurePerl by bobf

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.