Oh great monks, I find I am needful your wisdom. I am trying to use Twig to process an ungainly XML file as a stream of descrete parts. I am using ActivePerl 5.6.1.631 on Win32. I have used variations of the XML tools provided for Perl before for other tasks, but these files are too big for things like XPath, etc. I have loaded the Twig module and am trying to use the twig_roots function, since all I need to do is read data from the tags of interest and then purge the rest of the tree. When I run the code below I get this error message:
"Undefined subroutine &main:: called at C:/Perl/site/lib/XML/Parser/Expat.pm line 439."
In Expat.pm I see the following (lines 412 through 448):
sub parse {
my $self = shift;
my $arg = shift;
croak "Parse already in progress (Expat)" if $self->{Used};
$self->{Used} = 1;
my $parser = $self->{Parser};
my $ioref;
my $result = 0;
if (defined $arg) {
if (ref($arg) and UNIVERSAL::isa($arg, 'IO::Handler')) {
$ioref = $arg;
} else {
eval {
no strict 'refs';
$ioref = *{$arg}{IO};
};
}
}
if (defined($ioref)) {
my $delim = $self->{Stream_Delimiter};
my $prev_rs;
$prev_rs = ref($ioref)->input_record_separator("\n$delim\n")
if defined($delim);
$result = ParseStream($parser, $ioref, $delim); ### Line 439
ref($ioref)->input_record_separator($prev_rs)
if defined($delim);
} else {
$result = ParseString($parser, $arg);
}
$result or croak $self->{ErrorMessage};
}
The only thing I can think is that ParseStream is undefined. A quick search through the Expat, Parser, and Twig modules reveals no other instance of "ParseStream." What could be going on? I have used PPM to "verify --force update" all relevant modules, but to no avail.
Here is a snippet of my code:
#!C:/Perl
use XML::Parser;
use XML::Parser::Expat;
use XML::Twig;
my $t = XML::Twig->new(
twig_roots => {
'/invoice/header/accountnumber' => \&print_elt_text
} );
$t->parsefile('MyHugeXML.xml');
sub print_elt_text {
my( $t, $elt ) = @_;
print $elt->text;
$t->purge;
}
Thank you wise ones. Your wisdom is like ambrosia.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.