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: I can't STAND it (global variables)
by Mark - BLS CTR Thomas other posts by this author
Jul 21 2006 12:12PM messages near this date
view in the new Beta List Site
Re: SAX: I can't STAND it (global variables) | XML::LibXML::RelaxNG
& XSLT Arvinporthog wrote:
	
>  Man, I'm hating the whole SAX interface. I do not understand 
>  the appeal. Things seem set up to make chained filters and 
>  weird things like that easier but the drawback is everything 
>  is hugely more complicated. Make simple things simple my ass.
>  Even the littlest things are big enormous productions. Namespaces, 
>  global variables, callbacks--is this convenient for ANYONE? 
>  I've programmed SGML for over a decade so I understand the 
>  concepts and the event-driven model. 
	
SAX is my absolute last choice. I almost never use it. It's not meant to
be simple, it's meant to be efficient. There are usually better
alternatives (IMHO).

For example, the XML::LibXML code to check whether each file has a title
is:

foreach my $file (@xmlfiles) {
  my $doc = XML::LibXML-> new->parse_file($file);
  print "$file has title\n" if ($doc-> find('//title'));
}

If you're dealing with huge files and the DOM tree won't fit into
memory, you can use XML::Twig, a stream-based parser that has a more
perlish interface than SAX:

my $twig = XML::Twig-> new(
    twig_handlers =>  {
        'title' =>  sub { print "has title"; }
    }
);

foreach my $file (@xmlfiles) {
  print "$file ";
  $twig-> parsefile($file);
  print "\n";
}

Hope this helps.
- Mark.

-- 
Mark Thomas 
Internet Systems Architect
_______________________________________
BAE SYSTEMS Information Technology 
2525 Network Place
Herndon, VA  20171  USA 

_______________________________________________
Perl-XML mailing list
Perl-XML@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Arvinporthog
Petr Cimprich
Petr Cimprich
Martin Owens
Mark - BLS CTR Thomas

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