Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bigger XML::Simple Problem 1

Status
Not open for further replies.

pete1970

Programmer
Aug 16, 2007
10
US
Using:

Code:
my $doc = $xs1->XMLin($file, forcearray => 1, keyattr => {client_system => 'Customer Care'});

the Data::Dumper gives me:

Code:
$VAR1 = 
{
 'client_system' => [
    {
     'business_area' => [
        {
         'component' => [
            {
             'component_lib' => [
                {
                 'class_set' => [
                    {
                     'data_type' => '1',
                     'linked_name' => 'ACLI-4-MTH-AVG-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' => 'Active Strategy 2'
                }
             ]
          }
       ],
       'type' => 'class_set'
       }
    ]
  }
],
 'name' => 'GM Business Area',
 'analytics' => [
  {}
 ]
}
],
.
.
.

It's not formatted exactly correct but I basically want to get all of the interval=>names for the business_area client_system and so far I have:

Code:
my $doc = $xs1->XMLin($file, forcearray => 1, keyattr => {client_system => '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}{'name'}, "\n";
    }
}

or something like that. Probably have to loop through again to get all the interval names. Just confused with the syntax. Thanks in advance
 
If you don't use the forcearray attribute of XML::Simple, it won't try to force the output to become a whole bunch of arrayrefs within hashrefs, but only use arrayrefs when necessary (i.e. when there are a bunch of parallel tags with identical values), and then you can just get to each tag by name.

i.e.

Code:
$doc->{client_system}->{business_area}->{component}->{component_lib}->{class_set}->{data_type}

And none of these [square brackets], which become quite a pain to work with (using more hashes than arrays, you can quickly pull out a specific entry by name, instead of doing array loops).

-------------
Cuvou.com | My personal homepage
Project Fearless | My web blog
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top