Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: parse XML huge file using cpan modules

by choroba (Archbishop)
on Jul 28, 2019 at 19:48 UTC ( #11103542=note: print w/replies, xml ) Need Help??

in reply to parse XML huge file using cpan modules

For really large files, you can use XML::LibXML::Reader.
#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; use XML::LibXML::Reader; my $r = 'XML::LibXML::Reader'->new(location => shift); say 'time|resourceGroup|LCONNFAIL|LLOSTCONN|LIDLETIMEOUT|SIPADDR|SIPPO +RT'; my %dispatch = ( statRecord => sub { print $r->getAttribute('time'), '|'; }, resourceGroup => sub { print $r->getAttribute('name'); }, name => sub { my $name = $r->readInnerXml; return unless $name =~ /^(?:LCONNFAIL|LLOSTCONN|LIDLETIMEOUT|SIPADDR|SIPPORT)$ +/; $r->nextSiblingElement('value'); print '|', $r->readInnerXml; print "\n" if $name eq 'SIPPORT'; } ); while ($r->read) { next unless $r->nodeType == 1; my $action = $dispatch{ $r->name }; $action->() if $action; }

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^2: parse XML huge file using cpan modules
by nicopelle (Acolyte) on Jul 29, 2019 at 11:29 UTC
    @choroba , your code works flawless too ! Thanks for your support and not least for your teachings.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2020-09-25 16:28 GMT
Find Nodes?
    Voting Booth?
    If at first I donít succeed, I Ö

    Results (138 votes). Check out past polls.