XML::Rules, https://metacpan.org/module/XML::Rules#inferRulesFromExample, xml2XMLRules, Data::Diver :) references quick reference

#!/usr/bin/perl -- use strict; use warnings; use XML::Rules; use Data::Dump qw/ dd /; use Data::Diver qw/ Dive /; my $rawxml = q{<?xml version="1.0" encoding="UTF-8"?> <config> <log> <destination>e1@mail.de</destination> <destination>e2@mail.de</destination> <destination>e3@mail.de</destination> </log> <item> <id>0</id> <filename>file1</filename> <extension>txt</extension> </item> <item> <id>1</id> <filename>file2</filename> <extension>txt</extension> </item> </config> }; my $no_rules = XML::Rules->new( rules => [], )->parse( $rawxml ); dd( $no_rules ); my $xr = XML::Rules->new( qw/ stripspaces 8 /, #~ xml2XMLRules foo.xml #~ xml2XMLRules.bat foo.xml #~ #~ rules => XML::Rules->inferRulesFromExample( $rawxml ), rules => { 'extension,filename,id' => 'content', 'config,log' => 'no content', 'destination' => 'content array', 'item' => 'as array no content' }, ); my $ret = $xr->parse( $rawxml ); dd( $ret ); my $config = $ret->{config}; dd({ DESTINATIONS => int @{ $config->{log}{destination} } }); use Data::Diver qw/ Dive /; if( my $destinations = Dive( $ret, qw/ config log destination / ) ){ dd( { DESTINATIONS => int @$destinations, } ); } __END__ { config => { _content => "\n\t\n\t\n\t\n", item => { _content => "\n\t\t\n\t\t\n\t\t\n\t", extension => { _content => "txt" }, filename => { _content => "file2" }, id => { _content => 1 }, }, log => { _content => "\n\t\t\n\t\t\n\t\t\n\t", destination => { _content => "e3\@mail.de" }, }, }, } { config => { item => [ { extension => "txt", filename => "file1", id => 0 }, { extension => "txt", filename => "file2", id => 1 }, ], log => { destination => ["e1\@mail.de", "e2\@mail.de", "e3\@mail. +de"] }, }, } { DESTINATIONS => 3 } { DESTINATIONS => 3 }

In reply to Re: Problem with counting the nodes in a hash created by XML::Simple (use XML::Rules, Data::Diver ) by Anonymous Monk
in thread Problem with counting the nodes in a hash created by XML::Simple from a XML file. by turbodizik

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.