To add to the list of options...

use strict; use XML::Rules; use Data::Dumper qw(Dumper); my $parser = XML::Rules->new( stripspaces => 15, rules => { 'name,value' => 'content', statistic => sub { return '%' . $_[1]->{type} => { $_[1]->{nam +e} => $_[1]->{value}} }, resourceGroup => 'no content array', statRecord => sub { #print Dumper($_[1]); foreach my $group (@{$_[1]->{resourceGroup}}) { print "$_[1]->{time}|$group->{name}|$group->{Lifetime} +{LCONNFAIL}|$group->{Lifetime}{LLOSTCONN}|$group->{Lifetime}{LIDLETIM +EOUT}|$group->{Startup}{SIPADDR}|$group->{Startup}{SIPPORT}\n"; } return; } } ); print "time|resourceGroup name|LCONNFAIL|LLOSTCONN|LIDLETIMEOUT|SIPADD +R|SIPPORT\n"; $parser->parse(\*DATA); __DATA__ <?xml version="1.0" encoding="UTF-8"?> <ctgStatistics xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ctgstatslog.xsd"> <statRecord type="interval" length="60" time="2019-07-16T08:23:59"> <resourceGroup name="CSCS1SVGM1"> <statistic type="Startup"> ...
or
use strict; use XML::Rules; use Data::Dumper qw(Dumper); my $parser = XML::Rules->new( stripspaces => 15, rules => { 'name,value' => 'content', statistic => sub { return $_[1]->{name} => $_[1]->{value} }, resourceGroup => 'no content array', statRecord => sub { #print Dumper($_[1]); foreach my $group (@{$_[1]->{resourceGroup}}) { print "$_[1]->{time}|$group->{name}|$group->{LCONNFAIL +}|$group->{LLOSTCONN}|$group->{LIDLETIMEOUT}|$group->{SIPADDR}|$group +->{SIPPORT}\n"; } return; } } ); print "time|resourceGroup name|LCONNFAIL|LLOSTCONN|LIDLETIMEOUT|SIPADD +R|SIPPORT\n"; $parser->parse(\*DATA); __DATA__ <?xml version="1.0" encoding="UTF-8"?> <ctgStatistics xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ctgstatslog.xsd"> <statRecord type="interval" length="60" time="2019-07-16T08:23:59"> <resourceGroup name="CSCS1SVGM1"> <statistic type="Startup"> ...

The first version preserves the statistics type in the data provided to the handler of the statRecord tag, the second assumes there will be no duplicate names of statistics and ignores the types.

There's only the data from one <statRecord> in memory at any time.

Jenda
Enoch was right!
Enjoy the last years of Rome.


In reply to Re: parse XML huge file using cpan modules by Jenda
in thread parse XML huge file using cpan modules by nicopelle

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.