Hi,

I am having a small problem while parsing the XML code. First of all, here
comes snip of the sourcecode:

...
if ( $NN->[$j] eq "OBU" ) # if OBU was found...
{
  $OBU = $NN->[$j+1];

  for $e ( 0..@$OBU ) # loop through the content of OBU
  {
    if ( ref($OBU->[$e]) eq "HASH" )
    {
      $OBU_Attributes = $OBU->[$e];
      %OBU_hash = ( %OBU_hash, %$OBU_Attributes );
    }
  }
  $OBU_objects[$OBU_idx] = \%OBU_hash; # store the attributes
  $OBU_idx++; # increase the counter
}
...

I am using XML:Parser and tree model. As you probably might have figured
out, the problem comes with the loop that checks outs either there is hash
or not. There can be any number of OBU's. When I run the loop, every time
the program replaces the old value with the new value. The result (in the
end) is thereby the last node in the tree.

So, how can I put the values from different OBU's in the own
variables/hashes?
Does %OBU_hash[$index_value] = ... -solution work?

Additionally, here comes tree model taken with Data::Dumper:

             'OBU',
              [
                {
                  UID = 'FKDL',
                  MID => 'FDF3',
                  Version => 1,
                  Type => 'FD',
                  objectClass => 'OBU'
                },

              'OBU',
              [
                {
                  UID => 'FDF',
                  MID => 'FD4F',
                  Version => 1,
                  Type => 'F3U',
                  objectClass => 'OBU'
                },

              'OBU',
              [
                {
                  UID => '4T4',
                  MID => 'GFG4T',
                  Version => 1,
                  Type => '5GF',
                  objectClass => 'OBU'
                },

Hope you understood.. here comes even another example:

for ( $ind=0; $ind < @OBU_objects; $ind++ )
{      
  print "        UID : $FUUT_objects[$ind]->{UID}\n";
  print "        MID : $FUUT_objects[$ind]->{MID}\n";
  print "    Version : $FUUT_objects[$ind]->{Version}\n";
  print "       Type : $FUUT_objects[$ind]->{Type}\n";
  print "ObjectClass : $FUUT_objects[$ind]->{objectClass}\n";
}

when I run it, I got the exact value of the OBU_objects, but each of the
looks similar.

BR,
 Mika Aho

Reply via email to