Hi Octavian, On Thu, 25 Oct 2012 14:33:15 +0300 "Octavian Rasnita" <orasn...@gmail.com> wrote:
> Hi, > > Can you recommend an XML parser which is faster than XML::Twig? > > I need to use an XML parser that can parse the XML files chunk by chunk and > which works faster (much faster) than XML::Twig, because I tried using this > module but it is very slow. XML::LibXML contains several event-based parsers including the SAX parser and the pull-parser. Can you try using them? Regards, Shlomi Fish > > I tried something like the code below, but I have also tried a version that > just opens the file and parses it using regular expressions, however the > unelegant regexp version is 25 times faster than the one which uses > XML::Twig, and it also uses less memory. > > If you think there is a module for parsing XML which would work faster than > regular expressions, or if I can substantially improve the program which uses > XML::Twig then please tell me about it. If regexp will still be faster, I > will use regexp. > > Thanks. > > use XML::Twig; > > my $xml = 'path/to/xml/file.xml'; > > my $t= XML::Twig->new( twig_handlers => { > Lexem => sub { > my( $t, $lexem )= @_; > > my $id = $lexem->att( 'id' ); > my $timestamp = $lexem->first_child( 'Timestamp')->text; > my $lexem_text = $lexem->first_child( 'Form' )->text; > my @inflected_form = $lexem->children( 'InflectedForm' ); > > for my $inflected_form ( @inflected_form ) { > my $inflection_id = $inflected_form->first_child( 'InflectionId' > )->text; my $inflection_text = $inflected_form->first_child( 'Form' )->text; > } > > $t->purge; > > return 1; > }, > } ); > > $t->safe_parsefile( $xml ); > $t->purge; > > > --Octavian > > -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ Interview with Ben Collins-Sussman - http://shlom.in/sussman Modern Perl — the 3‐D Movie. In theatres near you. Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/