It's an older question, but as I haven't seen it suggested yet:
Perl with XML::Twig
can handle large XML files thanks to having a 'purge' method, which discards in memory data as you go.
use strict;
use warnings;
use XML::Twig;
my $twig = XML::Twig->new(
twig_handlers => {
_all_ => sub { $_->purge }
}
)->parsefile( 'my_xml_file.xml' );
The _all_
handler is triggered each element of the twig, and discards in memory data. That's important on a 4G file, because the memory footprint of XML is about 10x. But it'll throw an alert and abort if the XML is not well formed:
mismatched tag at line 12, column 27, byte 274 at C:/Perl/lib/XML/Parser.pm line 187.
(but bear in mind because it aborts, it'll only show you the first error it encounters).
Works on my (much smaller than 4G) sample data anyway.
man xmlwf
: "-r Normally xmlwf memory-maps the XML file before parsing; this can result in faster parsing on many platforms. -r turns off memory-mapping and uses normal file IO calls instead. Of course, memory-mapping is automatically turned off when reading from standard input." By the way, I assume you are using a 64-bit setup...