in reply to Reading multi-level-tag XML file

Now you know why XML::Simple says
The use of this module in new code is discouraged. Other modules are available which provide more straightforward and consistent interfaces. In particular, XML::LibXML is highly recommended.

You can solve your issues by using the ForceArray option to XMLin:

my $data = XMLin($xml_string, ForceArray => 1); for my $inf (@{ $data->{SellerInformation} }) { print $inf->{Seller}[0]{sellerIdFromProvider}, "\n"; for my $location (@{ $inf->{TaxableLocationsCollection}[0]{Taxable +Location} }) { print "\t", $location->{locationValue}, "\n"; } }
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: Reading multi-level-tag XML file
by CSharma (Sexton) on Jul 27, 2015 at 16:28 UTC
    Thanks Choroba! That worked. I want output like below, but getting unexpected results. All location values of all tags are coming for all seller entries. Something here is messy, Could you please help? sellerid comma seperated locations i.e. 426089 NY, CA, FL
    for my $inf (@{$data->{'SellerInformation'}}) { $sellerid = $inf->{'Seller'}[0]{'sellerIdFromProvider'}; $i = 0; for my $loc (@{$inf->{'TaxableLocationsCollection'}[0]{'TaxableLocatio +n'}}) { $location[$i++] = $loc->{'locationValue'}; } $location{$sellerid} = join(", ", @location); print $sellerid, "\t" . $location{$sellerid} . "\n"; }

      You are not clearing the @location array for each Seller. Try

      for my $inf (@{$data->{'SellerInformation'}}) { my $sellerid = $inf->{'Seller'}[0]{'sellerIdFromProvider'}; my @location=(); for my $loc (@{$inf->{'TaxableLocationsCollection'}[0]{'TaxableLocat +ion'}}) { push @location,$loc->{'locationValue'}; } print $sellerid."\t" .join(", ", @location)."\n"; }
      poj
        Thanks poj, got the required data!