A version based on the foreach / while idea:use XML::Simple; $data = XMLin( \*DATA, KeepRoot => 1, ForceArray => [ qw/attribute/ ] + ); @attrs = map { $_->{category} } # We want the c +ategory value map { @{ $_->{attributes}{attribute} } } # for each attr +ibute values %{ $data->{dataschemas}{dataschema} }; # in all datasc +hemas. print "@attrs\n"; __DATA__ <dataschemas> <dataschema name="varyingName1"> <attributes> <attribute category="one" fair="no" /> </attributes> </dataschema> <dataschema name="varyingName2"> <attributes> <attribute category="" parser="CSVParser" /> <attribute category="APS" internalCategory="aps" /> <attribute category="ASC" internalCategory="asc" /> <attribute category="ASMT" internalCategory="asmt" /> <attribute category="LE" internalCategory="l&e" /> <attribute category="NCO" internalCategory="nco" /> <attribute category="NEED TITLE" internalCategory="need title" + /> <attribute category="New Need ID" internalCategory="need id" / +> <attribute category="SUMMARY OF DELIVERABLES" parser="TextPars +er" extract="true" segmentation="hard" /> </attributes> </dataschema> </dataschemas>
foreach my $dataschema ( values %{ $data->{dataschemas}{dataschema} } +) { foreach my $attr ( @{ $dataschema->{attributes}{attribute} } ){ print "category is: ", $attr->{category}, "\n"; } }
In reply to Re^3: XML::Simple--dealing with a variable element
by rhesa
in thread XML::Simple--dealing with a variable element
by bw
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |