Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I'm not what you would call extremely experienced with XML, and see my machine consume all available (2.7gb) of ram before running out of memory on a pretty simple script.
#!/usr/bin/perl -w use strict; use XML::Twig; use Data::Dumper; $|++; my $t = XML::Twig->new( #twig_roots => { 'Person' => 1}, # uncommen +t to dump entire XML in a hr form twig_handlers => { 'Person' => \&person }, pretty_print => 'indented', keep_encoding => 1, ); $t->parsefile('./File.xml'); $t->flush; sub person { my ($t, $section) = @_; # my $root = $section->root(); # uncomment do dump entire xml in +a hr form my $id= $section->att('id'); my (@firstname, @middlename, @lastname, $description); my @para= $section->getElementsByTagName('Name'); foreach my $obj (@para) { if ($obj->att('NameType') eq 'Primary Name' ) { my $child = $obj->first_child('NameValue'); @firstname = $child->fields('FirstName'); @middlename= $child->fields('MiddleName'); @lastname = $child->fields('Surname'); } } my @list= $section->getElementsByTagName('Descriptions'); foreach my $obj (@list) { my $child = $obj->first_child('Description'); $description = $child->{'att'}->{'Description2'} if ($child->{'att +'}->{'Description2'}); } print "$id,$firstname[0],$middlename[0],$lastname[0],$description\ +n" if ($description); }
if someone could provide some insight or alternative(s) it would be appreciated!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: processing massive XML files with XML::Twig
by GrandFather (Saint) on Dec 05, 2008 at 04:31 UTC | |
by Anonymous Monk on Dec 05, 2008 at 04:54 UTC | |
|
Re: processing massive XML files with XML::Twig
by cutlass2006 (Pilgrim) on Dec 05, 2008 at 06:52 UTC | |
by mirod (Canon) on Dec 05, 2008 at 10:20 UTC | |
by myuserid7 (Scribe) on Dec 06, 2008 at 13:56 UTC | |
by Anonymous Monk on Dec 06, 2008 at 14:15 UTC | |
by myuserid7 (Scribe) on Dec 06, 2008 at 17:51 UTC | |
| |
by mirod (Canon) on Dec 07, 2008 at 10:50 UTC | |
by Anonymous Monk on Dec 07, 2008 at 21:52 UTC | |
| |
|
Re: processing massive XML files with XML::Twig
by Jenda (Abbot) on Dec 05, 2008 at 23:48 UTC |