XML::SAX::SimpleDispatcher - SAX handler to dispatch subroutines based on XPath like simple path and name of children tags under that node.
use XML::SAX::SimpleDispatcher; use XML::SAX::ParserFactory; my $stash; my $handler = XML::SAX::SimpleDispatcher->new( process => { '/Books/Book' => [ sub { push @$stash, $_[0]}, ['Title'] ], } ); my $parser = XML::SAX::ParserFactory->parser(Handler => $handler); $parser->parse_string('<Books><Book><Title>Learning Perl</Title></Book></Books>'); ## And then, $stash has a list of context inside of 'Title' tag
XML::SAX::SimpleDispatcher dispatches subroutine calls based on a XPath like path. This can be handy tweaking children nodes data while parsing data by SAX parser.
my $handler = XML::SAX::SimpleDispatcher->new( process => { '/MyShelf/Book' => [ sub { push @$stash, $_[0]}, ['Title'] ], '/MyShelf/Movie' => [ sub { push @$stash, $_[0]}, ['Title'] ], } );
Creates a new XML::SAX::SimpleDispatcher instance.
with process option, you can put a hash reference which has several paths as keys and array references of a list of subroutine reference and an array reference.
Well, it might not look simple but you can dispatch *characters* to each subroutine.
Masayoshi Sekimura <sekimura@cpan.org>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install XML::SAX::SimpleDispatcher, copy and paste the appropriate command in to your terminal.
cpanm
cpanm XML::SAX::SimpleDispatcher
CPAN shell
perl -MCPAN -e shell install XML::SAX::SimpleDispatcher
For more information on module installation, please visit the detailed CPAN module installation guide.