I need to stick with the use of XML::Simple only for now.

Sorry, but XML::Simple is almost never a good choice. Its own documentation says:

PLEASE DO NOT USE THIS MODULE IN NEW CODE. ... The use of this module in new code is strongly discouraged. ... The major problems with this module are the large number of options (some of which have unfortunate defaults) and the arbitrary ways in which these options interact - often producing unexpected results.

Please consider XML::LibXML, XML::Twig, or XML::Rules instead. A XML::LibXML solution:

use warnings; use strict; use XML::LibXML; my $doc = XML::LibXML->load_xml(IO=>*DATA); for my $product ($doc->findnodes('//product')) { my $item = $product->findvalue('./item_number'); my @colors = map {$_->textContent} $product->findnodes('.//color_swatch'); print "ITEM NUMBER: $item COLORS: @colors\n"; } __DATA__ <product description="watches" product_image="watches.jpg"> <item_number>QWZ5671</item_number> <size> <color_swatch image="red_watches.jpg">Red</color_swatch> <color_swatch image="burgundy_watches.jpg">Burgundy</color_swa +tch> </size> </product>

In reply to Re: XML access the repeating node values by haukex
in thread XML access the REPEATING NODE VALUES by Magnolia25

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.