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: SAX: I can't STAND it (global variables)
by Martin Owens other posts by this author
Jul 21 2006 12:16PM messages near this date
view in the new Beta List Site
Re: SAX: I can't STAND it (global variables) | RE: I can't STAND it (global variables)
& XSLT I wouldn't use SAX for that, it's far too low level. you want a DOM
where you can load the xml document and test for the tag using
standard w3c calls.

Try XML::Twig or XML::DOM2 (infact I would very much like you to try
XML::DOM2 because I it needs more testing)

On 7/21/06, arvinporthog <arvinporthog@[...].com>  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.
> 
>  OK, I exaggerate. I know SAX is probably very cool and I
>  just need to learn best practices and probably a bit more
>  about perl programming in general. But it's hard to be generous
>  whilst pulling your hair out. I post for you all a simple
>  example program and ask how it can be done without using
>  global variables and, optimally, namespaces. It takes a list
>  of xml files and checks for the presence of a required tag.
>  When the program is done it prints a list of the files and
>  whether or not they contained that tag.
> 
>  Arvin
> 
>  use XML::SAX;
>  use XML::SAX::ExpatXS;
>  use XML::Filter::BufferText;
>  use strict 'vars';
>  use vars qw($CurrentFile %Validated);
> 
>  my @xmlfiles = ('file1.xml', 'file2.xml', 'file3.xml');
> 
>  my $handler = new MySAXHandler;
>  my $filter = new XML::Filter::BufferText (Handler => $handler);
>  foreach my $file (@xmlfiles) {
>   $CurrentFile = $file;
>   $Validated{$file} = 'does not have title';
>   my $parser = XML::SAX::ParserFactory->parser(Handler =>
>  $filter);
>   $parser->parse_uri($file);
>  }
>  foreach my $file (keys %Validated) {
>   print "$file: $Validated{$file}\n";
>  }
> 
> 
>  package MySAXHandler;
>  use base qw(XML::SAX::Base);
> 
>  sub start_element {
>   my ($self, $e) = @_;
>   my $tag = $e->{LocalName};
>   if ($tag eq 'title') {
>   $main::Validated{$main::CurrentFile} = 'has title';
>   }
>  }
> 
> 
> 
> 
>  _______________________________________________
>  Perl-XML mailing list
>  Perl-XML@[...].com
>  To unsubscribe:
>  http://listserv.ActiveState.com/mailman/mysubs
> 
> 
> 
_______________________________________________
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