http://www.perlmonks.org?node_id=1050156


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

#!perl use strict; use warnings; use XML::Simple; use Data::Dump 'pp'; # input my $xml1 = infile('test.xml'); # process my $data = XMLin($xml1,keyattr => []); pp $data; # output for (@{$data->{'httpsRoute'}}){ print << "EOF"; Host = $_->{'hostname'} Environment = $_->{'environment'} Key = $_->{'key'} EOF } sub infile { my $filename = shift; local $/; #open IN,'<',$filename or die "Could not open $filename $!"; my $xml = <DATA>; # or IN return $xml; } __DATA__ <xml> <httpsRoute hostname="abchostname1.xxx.com" port="443" environment="QA +"> <key>6924</key> </httpsRoute> <httpsRoute hostname="hostname3.xxx.com" port="7416" environment="CAT" +> <key>9990068</key> </httpsRoute> </xml>
poj