If you don't insist on using XML::LibXML you could do something like this:
or (to match the second example)use strict; use XML::Rules; my $parser = XML::Rules->new( stripspaces => 7, rules => [ '_default' => 'content', 'Dev_Info' => sub { print "$_[1]->{dev_name}\t$_[1]->{configuration}\n"; return; }, 'Device' => '', ], start_rules => [ 'Hyper,RAID-5_Device,Back_End,Mirror_Set,Front_End,Product,Lab +el,Flags,Capacity' => 'skip', ], ); $parser->parse(\*DATA); __DATA__ <?xml version="1.0" standalone="yes" ?> <SymCLI_ML> ...
or to get rid of the global variable something likeuse strict; use XML::Rules; my %conf_of; my $parser = XML::Rules->new( stripspaces => 7, rules => [ '_default' => 'content', 'Device' => sub { $conf_of{$_[1]->{Dev_Info}{dev_name}} = "$_[1]->{Dev_Info} +{configuration},$_[1]->{Capacity}{cylinders}"; return; }, 'Dev_Info,Capacity' => 'no content', ], start_rules => [ 'Hyper,RAID-5_Device,Back_End,Mirror_Set,Front_End,Product,Lab +el,Flags' => 'skip', ], ); $parser->parse(\*DATA); use Data::Dumper; print Dumper(\%conf_of); __DATA__ <?xml version="1.0" standalone="yes" ?> <SymCLI_ML> ...
use strict; use XML::Rules; my %conf_of; my $parser = XML::Rules->new( stripspaces => 7, rules => [ '_default' => 'content', 'Device' => sub { return $_[1]->{Dev_Info}{dev_name} => "$_[1]->{Dev_Info}{c +onfiguration},$_[1]->{Capacity}{cylinders}"; }, 'Dev_Info,Capacity' => 'no content', 'Symm_Info' => sub {return symid => $_[1]->{symid}}, 'Symmetrix' => 'no content', 'SymCLI_ML' => 'pass', ], start_rules => [ 'Hyper,RAID-5_Device,Back_End,Mirror_Set,Front_End,Product,Lab +el,Flags' => 'skip', ], ); my $conf = $parser->parse(\*DATA); use Data::Dumper; print Dumper($conf); __DATA__ <?xml version="1.0" standalone="yes" ?> <SymCLI_ML> ...
Your requirements do look like something that XML::Rules was designed for.
In reply to Re: Any help available for a newbie to XML::LibXML?
by Jenda
in thread Any help available for a newbie to XML::LibXML?
by wardy3
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |