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>