Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Problem with counting the nodes in a hash created by XML::Simple (use XML::Rules, Data::Diver )

by Anonymous Monk
on Jul 18, 2013 at 13:22 UTC ( [id://1045094]=note: print w/replies, xml ) Need Help??


in reply to Problem with counting the nodes in a hash created by XML::Simple from a XML file.

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 }
  • Comment on Re: Problem with counting the nodes in a hash created by XML::Simple (use XML::Rules, Data::Diver )
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1045094]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-20 04:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found