Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

XML::Checker::Parser - one object, multiple files?

by rekoil (Novice)
on Jan 22, 2008 at 00:20 UTC ( [id://663487]=perlquestion: print w/replies, xml ) Need Help??

rekoil has asked for the wisdom of the Perl Monks concerning the following question:

I'm using XML::Check::Parser to do a DTD validation on a set of files. While it's not a problem to validate a single file, I run into issues when I attempt to use the parsefile() method against multiple files:
my $checker = new XML::Checker::Parser(Handlers => {}); foreach ($files) { print "Checking file $_ ...\n"; eval { $checker->parsefile($_); }; if ($@) { (print $error) } }
What happens is that once the second file is loaded, the checker reports DTD errors that make it look like it still thinks I'm reading in a single file:
Checking file file1.xml ... Checking file file2.xml ... (115, ELEMENT [foo] already defined Element foo line 2 column 67 byte +90) Checking file file3.xml ... (115, ELEMENT [foo] already defined Element foo line 2 column 67 byte +90) ...
I can get around this by putting the my $checker = new XML::Parser::Checker ... line inside the foreach loop, but that seems terribly inelegant to me. Is there a better way to do this? Is there a method in XML::Checker::Parser I'm not seeing to tell it to expect a new complete XML file?

Replies are listed 'Best First'.
Re: XML::Checker::Parser - one object, multiple files?
by Fletch (Bishop) on Jan 22, 2008 at 02:07 UTC

    Why's it inelegant? The parser has to maintain an internal state as it parses the document in addition to on top of the bare state of a new instance. If there were some huge amount of work to be done in creating that new bare instance then it'd probably be worth antagonizing over, but in this particular case the "savings" in "only" throwing away the document state (were some mechanism in the underlying XML::Parser even available to do this in the first place; since it doesn't it's a moot question :) versus just making a new parser instance is more than likely negligible and not worth fretting over.

    Update: Gah, tweaked some phrasing and put a phrase back in that got dropped between brane and fingers.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re: XML::Checker::Parser - one object, multiple files?
by Cody Pendant (Prior) on Jan 22, 2008 at 03:41 UTC
    Can't you just set $@ to undef after you've printed it?


    Nobody says perl looks like line-noise any more
    kids today don't know what line-noise IS ...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://663487]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-26 04:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found