in reply to Re^2: XML: Simple - nested XML data
in thread XML: Simple - nested XML data

My attempts to access the single item have still failed. :(

Fear not, my good monk, for perldsc, perlref, perlreftut are with you. Just drill down one level at a time.

use strict; use warnings; use Data::Dumper; use XML::Simple; my $xml = q{ <SuperItem> <UserID>1234</UserID> <MajorItems> <MinorItem> <Item>Box</Item> </MinorItem> </MajorItems> <MajorItems> <MinorItem> <Item>Suitcase</Item> </MinorItem> </MajorItems> </SuperItem> }; my $struct = XMLin( $xml, ForceArray => 1 ); dumpit( $struct ); my $MajorItems_aref = $struct->{MajorItems}; dumpit( $MajorItems_aref ); my $SecondMinorItem_href = $struct->{MajorItems}[1]; # or $MajorItems_aref->[1] dumpit( $SecondMinorItem_href ); my $MinorItem_aref = $struct->{MajorItems}[1]{MinorItem}; # or $SecondMinorItem_href->{MinorItem} dumpit( $MinorItem_aref ); my $MinorItemFirst_href = $struct->{MajorItems}[1]{MinorItem}[0]; # or $MinorItem_aref->[0] dumpit( $MinorItemFirst_href ); my $Item_aref = $struct->{MajorItems}[1]{MinorItem}[0]{Item}; # or $MinorItemFirst_href->{Item} dumpit( $Item_aref ); my $luggage = $struct->{MajorItems}[1]{MinorItem}[0]{Item}[0]; # or $Item_aref->[0] dumpit( $luggage ); sub dumpit { print Dumper( $_[0] ); }

Replies are listed 'Best First'.
Re^4: XML: Simple - nested XML data
by dmaranan (Acolyte) on Dec 28, 2007 at 15:04 UTC
    My attempts have succeeded. My thanks to you!