note
mirod
<p>XML::Twig can (and is actually designed to) parse big document. It doesn't do it by using an incremental parser, but by building a (non-DOM) tree for each element it parses. It lets you call handlers on elements, using the <tt>twig_handlers</tt> or <tt>twig_roots</tt> options. These handlers are called as soon as the element is completely parsed. In the handler you can process the element, then release the memory it used, by calling <tt>purge</tt> or <tt>flush</tt> (which also outputs the tree so far). This doesn't work when you need to have the entire tree available for processing, but in practice it does work in most cases, where you can treat the overall XML as a collection of independant elements. See the section <i>Processing an XML document chunk by chunk</i> in the docs.</p>
<p>Using XML::Parser incremental parsing methods probably works in XML::Twig, I just never tested it, because that's not what XML::Twig needs. It does just fine with the regular interface, calling handlers during parsing.</p>
<p>XML::LibXML offers a different interface to parse incrementally the XML, look into [cpan://XML::LibXML::Reader].</p>
951798
951822