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.


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

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.