in reply to Re^3: XML::Simple Multi-Layered
in thread XML::Simple Multi-Layered

Thank you, that works. However, now I am still having issues with my original XML above. Using:
my $doc = $xs1->XMLin($file, forcearray => 1, keyattr => {client_syste +m => 'Customer Care'});
then Data::Dumper gives me output like this:
$VAR1 = { 'client_system' => [ { 'business_area' => [ { 'component' => [ { 'component_lib' => [ { 'class_set' => [ { 'data_type' => '1', 'linked_characteristic_name' => '4-MTH-AV +G-UTIL', 'version' => '2.0', 'name' => 'Active Strategy 2', 'is_protected' => 'false', 'base_class_set' => [ { 'interval' => [ { 'outcome' => [ { 'uniqueID' => '2', 'displayPosition' => '1', 'name' => 'low-199' } ], 'is_Others' => ['false'], 'range' => ['low-199'], 'name' => 'low-199' + + + }, + + { + + 'outcome' => [ + + + { + + 'uniqueID' => '3', + + + 'displayPosition' => '2', + + + 'name' => '200-499' } ], 'is_Others' => ['false'], 'range' => ['200-499'], 'name' => '200-499' }, { 'outcome' => [ { 'uniqueID' => '4', 'displayPosition' => '3' +, 'name' => '500-899' } ], 'is_Others' => ['false'], 'range' => ['500-899'], 'name' => '500-899' }, { 'outcome' => [ { 'uniqueID' => '1', 'displayPosition' => +'2147483647', 'name' => 'Others' } ], 'is_Others' => ['true'], 'name' => 'Others' } ] } ], 'obj_info' => [ { 'obj_revision' => '1', 'version' => '2.0', 'name' => 'CS A1524 CD GM Active Strategy +2', 'library_unique_id' => '00000071', } ] } ], 'type' => 'class_set' } ] } ], 'name' => 'GM Business Area', 'analytics' => [ {} ] } ], . . .
Sorry for the mess but I'm tired of formatting. Anyway, I basically want to get all of the interval=>names for the business_area client_system and I have:
my $doc = $xs1->XMLin($file, forcearray => 1, keyattr => {client_syste +m => 'Customer Care'}); foreach my $key (keys (%{$doc->{client_system}})){ if($key eq 'business_area') { print $doc->{client_system}[$key]->{component}[0]->{component_ +lib}[0]->{class_set}[0]->{base_class_set[0]->{interval}{'range'}, "\n +"; } }
or something like that. Just confused with the syntax on the print command. Probably also have to loop through again to get all the interval names. Thanks in advance

Replies are listed 'Best First'.
Re^5: XML::Simple Multi-Layered
by wfsp (Abbot) on Aug 17, 2007 at 11:59 UTC
    For the sake of example I've stripped down the data to just leave the bits we're looking at. (note the $Data::Dumper::Indent = 1; line, it compacts Dumper's output a bit).

    You have a series of nested hash of arrays (HoAs).

    Here I've extracted the array ref we want and looped over it.

    output:

    low-199 200-499 500-899 Others

    fwiw
    I find that setting tabs to spaces with a tab setting of 2 can help make code a bit more readable