Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: parse XML huge file using cpan modules

by poj (Abbot)
on Jul 28, 2019 at 16:10 UTC ( #11103539=note: print w/replies, xml ) Need Help??


in reply to parse XML huge file using cpan modules

Try building a hash from the name/value elements within each resourceGroup. Example using XML::Twig

#!/usr/bin/perl use strict; use XML::Twig; #time|resourceGroup name|LCONNFAIL|LLOSTCONN|LIDLETIMEOUT|SIPADDR|SIPP +ORT my @columns = ('resourceGroup', 'LCONNFAIL','LLOSTCONN','LIDLETIMEOUT','SIPADDR','SIPPORT'); my $time; my %record = (); # tag handler my $twig = XML::Twig->new( twig_handlers => { resourceGroup => \&resourceGroup, statistic => \&statistic, }, start_tag_handlers => { statRecord => sub { $time = $_[1]->att('time') } } ); # process file print join '|','time',@columns; print "\n"; $twig->parsefile( 'my_file.xml' ); sub resourceGroup { my ($t,$e) = @_; $record{'resourceGroup'} = $e->att('name'); # print record print join "|",$time,map{$record{$_}}@columns; print "\n"; $t->purge; %record = (); } sub statistic { my ($t,$e) = @_; my $name = $e->first_child_text('name'); $record{$name} = $e->first_child_text('value'); }
poj

Replies are listed 'Best First'.
Re^2: parse XML huge file using cpan modules
by nicopelle (Acolyte) on Jul 28, 2019 at 17:26 UTC
    @Poj your code work flawless !
    Thanks for your support!!!!.
    And overall, thanks for teaching me how to interact correctly with the xml file

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2019-12-11 03:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?