Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^3: Incremental XML parsing

by mirod (Canon)
on Feb 05, 2012 at 07:59 UTC ( #951924=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Incremental XML parsing
in thread Incremental XML parsing

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 twig_handlers or twig_roots 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 purge or flush (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 Processing an XML document chunk by chunk in the docs.

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.

XML::LibXML offers a different interface to parse incrementally the XML, look into XML::LibXML::Reader.


Comment on Re^3: Incremental XML parsing
Re^4: Incremental XML parsing
by Anonymous Monk on Feb 05, 2012 at 11:32 UTC
    XML::LibXML offers a different interface to parse incrementally the XML, look into XML::LibXML::Reader.
    It's like nobody's reading the entire thread. I specifically asked about using XML::LibXML::Reader in my OP.

      It's like nobody's reading the entire thread. I specifically asked about using XML::LibXML::Reader in my OP.

      You also asked Or is there a better alternative?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://951924]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (17)
As of 2014-07-24 13:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (160 votes), past polls