You can either print the samplings as you parse the XML:
use strict; use XML::Rules; my $parser = XML::Rules->new( rules => { _default => 'content', 'sampling,sports' => 'content array', dataName => sub { return unless $_[1]->{language} eq 'English'; return $_[0] => $_[1]; }, place => sub { return unless $_[1]->{country} eq 'SouthAfrica'; print "Sampling: " . join( ', ', @{$_[1]->{dataName}{sampl +ing}}) . "\n"; return; } } ); $parser->parse(\*DATA); __DATA__ <?xml version="1.0" encoding="utf-8" ?> <request> <place> <country>SouthAfrica</country> <sports>cricket</sports> <sports>rugby</sports> <dataName> <language>English</language> <sampling>16000</sampling> <sampling>11025</sampling> </dataName> <dataName> <language>Africans</language> <sampling>16000</sampling> </dataName> </place> </request>
or extract the data you need in an easy to use format and print what you need then:
use strict; use XML::Rules; my $parser = XML::Rules->new( rules => { _default => 'content', 'sampling,sports' => 'content array', dataName => sub { return delete($_[1]->{language}) => $_[1]; }, place => sub { return delete($_[1]->{country}) => $_[1]; }, request => 'pass', }, stripspaces => 7 ); my $data = $parser->parse(\*DATA); #use Data::Dumper; #print Dumper($data); print "Sampling: " . join( ', ', @{$data->{SouthAfrica}{English}{sampl +ing}}) . "\n"; __DATA__ <?xml version="1.0" encoding="utf-8" ?> ...

In reply to Re: Problem traversing nested nodes XML::Simple by Jenda
in thread Problem traversing nested nodes XML::Simple by quickskate

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.