in reply to Any help available for a newbie to XML::LibXML?

If you don't insist on using XML::LibXML you could do something like this:

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 match the second example)
use 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> ...
or to get rid of the global variable something like
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.

Replies are listed 'Best First'.
Re^2: Any help available for a newbie to XML::LibXML?
by wardy3 (Scribe) on Mar 04, 2008 at 23:49 UTC

    Thanks, Jenda. I had a play with your module. It's quite interesting and pretty fast.

    At the moment, I've been playing with XSLT, which I started learning a few years ago but stopped using it. It's performing very fast too, so I'm going to go down that road for now.

    But that you very much for your suggestions - I've created some working test scripts based on your code - and I'll look into XML::Rules when I'm back in the XML world again :-)