Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: parse XML huge file using cpan modules

by poj (Abbot)
on Jul 28, 2019 at 16:10 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11103539]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (6)
As of 2024-03-29 12:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found