Catharsis has asked for the wisdom of the Perl Monks concerning the following question:
Im using XML::Twig to process a rather large XML document. have a look at the example below (moved from the scratchpad on advise below) It seams to Segfault no matter where I force it to exit the loop, or how.
Trouble here is that I HAVE to process the archive tag first, it has some information that is required for the rest of the code to work (shortened for example).
The alternative is of course to change the xml.. to
<archive>
<important_tag info="here">
<directory path="foo/"/>
<directory path="foo/bar/"/>
<directory path="foo/wibble/"/>
</archive>
Code follows....
#!/usr/bin/perl
use XML::Twig;
my $twig = new XML::Twig( TwigHandlers => {
archive => \&process_archive,
} );
open FILE, 'new.xml' or die ("arrrrrrrrrrgh");
read (FILE, $data, (-s 'new.xml'));
close FILE;
# dont work, note the file is 17MB of XML
#$twig->parse( $data );
# works
$twig->parse( \*DATA );
sub process_archive {
my ($t, $elt) = @_;
## grab and process attributes
my @children = $elt->children;
my $count = 0;
my $last = 0;
foreach ( @children ) {
$count++;
print "Processing Directory ".$count." of ".scalar @children."\n";
last if ($count eq 2);
}
}
__DATA__
<archive info="here">
<directory path="foo/"/>
<directory path="foo/bar/"/>
<directory path="foo/wibble/"/>
</archive>
But it only does it with large docs, the small doc in the example works fine!
Some version info as requested. I know there is a newer version of XML::Twig out there, but Ive yet to try it.
OS: Linux - Fedora Core Arcitecture : i386 Perl version : 5.8.1 XML::Twig ver : 3.17 XML::Parser ver : the one shipped with 5.8.1
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XML::Twig segfaulting on large docs
by Tanktalus (Canon) on Sep 27, 2005 at 17:13 UTC | |
|
Re: XML::Twig segfaulting on large docs
by mirod (Canon) on Sep 27, 2005 at 19:08 UTC | |
by Catharsis (Initiate) on Oct 03, 2005 at 11:44 UTC |