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
|