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] ); }


In reply to Re^3: XML: Simple - nested XML data by bobf
in thread XML: Simple - nested XML data by dmaranan

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.