ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl-xml
perl-xml
[RE]Re: SAX: I can't STAND it (global variables)
by Arvinporthog other posts by this author
Jul 24 2006 8:27AM messages near this date
view in the new Beta List Site
[RE]Re: SAX: I can't STAND it (global variables) | Install XML::Parser still failing
& XSLT Thanks for the tip. I didn't know that about ExpatXS
<br> and buffer text. SAX does seem like it might be useful
<br> for a program whose primary function is to parse XML
<br> files (efficiency), but as a tiny piece of a larger
<br> program that has little to do with XML I am swearing
<br> it off for good.
<br> 
<br> >$parser->{foo} should be $parser->{Handler}{foo} in fact.
<br> >(foo = 'title|file')
<br> 
<br> I'm really glad you made that clear. I was wondering
<br> about that. In my program I put the parser creation
<br> within my loop as a cheap way of reinitializing the
<br> state maintained in the handler with each new file
<br> (I'm storing a lot more than just the title in my full
<br> program and saving it for the end when I print a
<br> detailed report). What do you think of this method?
<br> Does it add a lot of overhead creating and destroying
<br> a new object with each iteration? Would I be better
<br> served using just a single object instantiated once
<br> and reinitializing just the bits I need?
<br> 
<br> Arvin
<br> 
<br> 
<br> 
<br> 
<br> ---------[ Received Mail Content ]----------
<br> >Subject : Re: SAX: I can't STAND it (global variables)
<br> >Date : Mon, 24 Jul 2006 08:36:31 +0200
<br> >From : Petr Cimprich <petr@[...].cz>
<br> >Cc : arvinporthog <arvinporthog@[...].com>,        Perl-XML <Perl-XML@[...].com>
<br> >
<br> >Errata:)
<br> >
<br> >$parser->{foo} should be $parser->{Handler}{foo} in fact.
<br> >(foo = 'title|file')
<br> >
<br> >> 
<br> >> ------------------------------------------------------------------------
<br> >> 
<br> >> use XML::SAX;
<br> >> use XML::SAX::ExpatXS;
<br> >> 
<br> >> my @xmlfiles = ('file1.xml', 'file2.xml', 'file3.xml');
<br> >> 
<br> >> my $handler = new MySAXHandler;
<br> >> my $parser = XML::SAX::ExpatXS->new(Handler => $handler);
<br> >> 
<br> >> foreach my $file (@xmlfiles) {
<br> >>     $parser->{file} = $file;
<br> >>     $parser->{title} = 'does not have title';
<br> >> 
<br> >>     $parser->parse_uri($file);
<br> >> 
<br> >>     print "$file: $parser->{title}\n";
<br> >> }
<br> >> 
<br> >> package MySAXHandler;
<br> >> use base qw(XML::SAX::Base); 
<br> >> 
<br> >> sub start_element {
<br> >>     my ($self, $e) = @_;
<br> >>     $self->{title} = 'has title' if $e->{LocalName} eq 'title';
<br> >> }
<br> >> 
<br> >> 
<br> >> ------------------------------------------------------------------------
<br> >> 
<br> >> _______________________________________________
<br> >> Perl-XML mailing list
<br> >> Perl-XML@[...].com
<br> >> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
<br> >
<br> >
<br> >-- 
<br> >Petr Cimprich
<br> >Ginger Alliance
<br> >www.gingerall.com
<br> >
<br> >
<br> 
Thread:
Arvinporthog
Arvinporthog
Ben Syverson
Aram Mirzadeh
Ben Syverson
Ben Syverson

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved