Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^4: Perl XML::Smart Out of memory! error

by nasaa (Novice)
on Apr 28, 2014 at 22:53 UTC ( [id://1084206]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Perl XML::Smart Out of memory! error
in thread Perl XML::Smart Out of memory! error

Hi many thanks for the code. i ran it on the full file and it showed up an error while processing. Can't call method "att" on an undefined value at import_icecat.pl line 107. line 107 is
$f[3] = $elt->first_child('Description[@langid="1"]')->att('Value');
looking at the xml i find that there is block with missing attributes.It has the opening and closing Category tag but not discription.How do i get it to ignore where tags are missing and keep processing
<Category ID="1" LowPic="" Score="0" Searchable="0" ThumbPic="" UNCA +TID="" Visible="0"> <Name ID="0" Value="" langid="1"/> <ParentCategory ID="1"/> </Category>

Replies are listed 'Best First'.
Re^5: Perl XML::Smart Out of memory! error
by poj (Abbot) on Apr 29, 2014 at 07:55 UTC

    Try

    sub Category{ my ($t, $elt) = @_; my @f = ( $elt->att('ID') ,'','','','','' ); $f[4] = $elt->att('LowPic'); $f[5] = $elt->att('ThumbPic'); $f[1] = $elt->first_child('ParentCategory')->att('ID'); for my $e ($elt->children('@langid="1"')){ $f[2] = $e->att('Value') if $e->name eq 'Name'; $f[3] = $e->att('Value') if $e->name eq 'Description'; } print "@f\n"; $sth->execute(@f); }
    poj
Re^5: Perl XML::Smart Out of memory! error
by Anonymous Monk on Apr 28, 2014 at 22:59 UTC
    block eval, like  $f[3] = eval { $elt->first_child('Description[@langid="1"]')->att('Value'); }; so if there is no first_child ... and no att value ... the program keeps going

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1084206]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-25 05:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found