in reply to extracting attribute values which might have multiple occurences from xml file

XML::Twig
use warnings; use strict; use XML::Twig; my $twig = XML::Twig->new( twig_handlers => { httpsRoute => \&httpsRou +te } ); $twig->parsefile('test.xml'); sub httpsRoute { my ( $twig, $httpsRoute ) = @_; print $httpsRoute->att('hostname'), "\n"; print $httpsRoute->att('tier'), "\n"; print $httpsRoute->first_child('key')->text(), "\n"; print "\n"; } __END__ hostname1.xxx.com dmz 6924 hostname3.xxx.com dmz 9990068

Use open to print to a file.

  • Comment on Re: extracting attribute values which might have multiple occurences from xml file
  • Download Code

Replies are listed 'Best First'.
Re^2: extracting attribute values which might have multiple occurences from xml file
by perlDevsWorld (Novice) on Jan 30, 2015 at 20:13 UTC
    Thanks a bunch!. This is working like a magic. Great help. Thanks a ton!.