The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

ETR::XML::SAX::FilterHandler - A handler to filter large XML files or streams

VERSION

Version 0.02

SYNOPSIS

 use ETR::XML::SAX::FilterHandler;
 use XML::SAX::ParserFactory;
 my $hnd = ETR::XML::SAX::FilterHandler->new({

        root            => books,
        record          => {
                                entry       => 1,
                                other_entry => 1
                        },
        find_data       => {
                                "Title 1" => 1,
                                "Title 3" => 1,
                                Oth       => 1
                        }
 });
 my $str=<<EOS;
 <books>
   <entry>
     <title>Title 1</title>
   </entry>
   <other_entry>
     <title>Other title</title>
   </other_entry>
   <entry>
     <title>Title 2</title>
   </entry>
   <entry>
     <title>Title 3</title>
   </entry>
 </books>
 EOS
 my $factory = XML::SAX::ParserFactory->parser(Handler => $hnd);

 # XML source:

 # from string:
 print "\nfrom string:\n======\n";
 $factory->parse_string($str);

 # from file
 print "\nfrom file:\n======\n";
 $factory->parse_file("books.xml");

 # from standard input
 print "\nfrom standard input:\n======\n";
 $factory->parse_file(*STDIN);

Every time you should receive the following result:

 <books>
   <entry>
     <title>Title 1</title>
   </entry>
   <other_entry>
     <title>Other title</title>
   </other_entry>
   <entry>
     <title>Title 3</title>
   </entry>
 </books>

DESCRIPTION

Parse large XML files or streams without being loaded into memory and print to the standard output only the fragments that match to the filtering rules specified by the two parameters: record and find_data.

METHODS

new()

 new({ 
        root    => document_root,
        record  => {
                entry1 => 1,
                entry2 => 1,
                ...
                entrym => 1
        }
        find_data => {
                str1 => 1,
                str2 => 1,
                ...
                strn => 1
        }
 })

Parameters:

        root:           a string used to enclose the whole document;

        record:         is a hash with element names considered as being record
                        delimiters;

        find_data:      the record is printed out if at least one string from this hash 
                        matches to the xml data.

        Note: The values from the two hashes have to be set to 1, just to force key to be
        defined.

AUTHOR

Daniel Necsoiu, Ericsson, <daniel.necsoiu@gmail.com; daniel.necsoiu@ericsson.com>

BUGS

Please report any bugs or feature requests to bug-etr-xml-sax-filterhandler at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=ETR-XML-SAX-FilterHandler. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc ETR::XML::SAX::FilterHandler

You can also look for information at:

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

Copyright 2015 Daniel Necsoiu, Ericsson.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.