I am trying to parse some big xml files while not eating all the user memory, so XML::SAX::Parser seems to be the solution.

The solution is called XML::Twig, see http://xmltwig.org/tutorial/

update: It seems you're already aware of twig,

anyway, the docs aren't clear what is supposed to be going on, but the information is out there :) use xml_decl handler

#!/usr/bin/perl -- use strict; use warnings; use XML::SAX; use Module::Load qw/ load /; my @files = ( ... ); my $parsers = XML::SAX->parsers(); for my $parser ( @$parsers ){ load( $parser->{Name} ); print "\n$parser->{Name}\n"; for my $file ( @files ){ $parser->{Name}->new( Handler => MySAXHandler->new, )->parse_file( $file ); } } package MySAXHandler; use base qw( XML::SAX::Base ); use Data::Dump qw/ pp /; sub start_document { _pper('doc', @_ ) } sub start_dtd { _pper('dtd', @_ ) } sub xml_decl { _pper('decl', @_ ) } sub _pper { my ($name, $self, $doc) = @_; print " $name ", pp( %$doc ), "\n"; } __END__ XML::SAX::Expat doc ("Version", "1.0", "Encoding", "UTF-8", "Standalone", "") doc ("Version", "1.0", "Encoding", "ISO-8859-1", "Standalone", "") doc () XML::LibXML::SAX::Parser doc () decl ("Version", "1.0", "Encoding", "UTF-8") doc () decl ("Version", "1.0", "Encoding", "ISO-8859-1") doc () decl ("Version", "1.0", "Encoding", undef) XML::LibXML::SAX doc () decl ("Version", "1.0") doc () decl ("Version", "1.0", "Encoding", "ISO-8859-1") doc () decl ("Version", "1.0")

In reply to Re: XML::SAX::ParserFactory policy and differences between parser implementations by beech
in thread XML::SAX::ParserFactory policy and differences between parser implementations by seki

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.