Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I parse large XML files in Perl?

Tags:

xml

perl

sax

Does reading XML data like in the following code create the DOM tree in memory?

my $xml = new XML::Simple;

my $data = $xml->XMLin($blast_output,ForceArray => 1);

For large XML files should I use a SAX parser, with handlers, etc.?

like image 402
Ashika Umanga Umagiliya Avatar asked Nov 29 '22 06:11

Ashika Umanga Umagiliya


1 Answers

For large XML files, you can either use XML::LibXML, in DOM mode if the document fits in memory, or using the pull mode (see XML::LibXML::Reader) or XML::Twig (which I wrote, so I'm biased, but it works generally well for files that are too big to fit in memory).

I am not a fan of SAX, which is hard to use and in fact quite slow.

like image 147
mirod Avatar answered Dec 16 '22 10:12

mirod