From:                   Andrew Curry <[EMAIL PROTECTED]>
> If you look at $data for the problem file its not an array at that point.
> For a single element XML::Simple doesn't display your data in a list i.e. 
> 
> With 1 element of record.
> 
> $VAR1 = {
>           'RECORD' => {
>                       'COLLNAME' => 'FBIS2004',
>                       'DOCI' => 'CP1'
>                     }
>         };
> 
> With 2 elements of record.
> 
>  $VAR1 = {
>           'RECORD' => [
>                       {
>                         'COLLNAME' => 'FBIS2004',
>                         'DOCI' => 'CP1'
>                       },
>                       ' BOOB'
>                     ]
>         };
> 
> So you cant do @{$data->{RECORD}} as it doesn't exist when there is only 1
> element.
> You can either test that its an arrayref or hashref or you could use
> something like XML::Parser, Lib:XML

Or you can tell XML::Simple that you expect the <RECORD> to be 
repeated and therefore want it to be an array always. Have a look at 
the forcearray option.

And if your XML starts to get too big to fit in memory have a look at 
XML::Rules.

my $parser = XML::Rules->new(
  rules => [
   _default => 'content',
   RECORD => sub {
     do whatever you need with the record
     the data are in $_[1]->{COLLNAME} and $_[1]->{DOCI}

     return; # don't remember the data for the RECORD anymore
   },
   DATA => '',
  ]
);

$parser->parsefile('test.xml');

Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to