And here's an XML::Rules example:
#!/usr/bin/perl use strict; use warnings; use XML::Rules; my @rules = ( _default => sub {$_[0] => $_[1]->{_content}}, query => sub { print "$_[1]->{name}: $_[1]->{topN}\n" }, ); my $r = XML::Rules->new(rules => \@rules); $r->parse(\*DATA); __END__ <?xml version='1.0'?> <queries> <query> <name>topHosts</name> <layer>LINK</layer> <topN>20</topN> <datatype>topHosts</datatype> <filter></filter> </query> <query> <name>topHosts</name> <layer>LINK</layer> <topN>120</topN> <datatype>topHosts</datatype> <filter></filter> </query> </queries>
Here's an alternate example:
use strict; use warnings; use XML::Rules; use Data::Dumper qw(Dumper); my @rules = ( _default => 'content', # Default filter to 'None' (v5.10 syntax here) filter => sub { $_[1]{_content} //= 'None'; $_[0] => $_[1]{_conten +t} }, query => 'no content array', queries => 'pass no content', ); my $r = XML::Rules->new(rules => \@rules); my $data = $r->parse(\*DATA); # Assume same data as above print Dumper $data; # Output $VAR1 = { 'query' => [ { 'topN' => '20', 'layer' => 'LINK', 'filter' => 'None', 'name' => 'topHosts', 'datatype' => 'topHosts' }, { 'topN' => '120', 'layer' => 'LINK', 'filter' => 'None', 'name' => 'topHosts', 'datatype' => 'topHosts' } ] };

In reply to Re^2: XML parsing problem by runrig
in thread XML parsing problem by avi_2009

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.