etlamar has asked for the wisdom of the Perl Monks concerning the following question:
Can anyone help me change Handlers in XML::Parser?
Code excerpt is as follows:
#!/usr/bin/perl -w use strict; use XML::Parser; open (FILEA, "File.txt"); my $parser = XML::Parser->new(); $parser->setHandlers(Start => \&handle_start, Char => \&handle_char, End => \&handle_end1, Final => \&final1); $parser-parsefile('File2.txt'); my $char_array_ref; my @end_array; sub handle_start{ my $e = shift; my $start_element = shift; if ($start_element eq 'coordinates'){print "hello.\n"; $parser->setHandlers(Char => \&coord); } } sub handle_char{ my $e = shift; print "HELLO There\n."; } sub coord{ my $e = shift; print "hello again.\n"; }
Use of print commands serve as a test to see which subroutines are called on Char events.
I never see "hello again" printed to the screen.
The Expat documentation suggests that you can change a handler conditionally as I am trying to do.
But I cannot seem to get it to work.
Can anyone point me in the right direction?
I would be very much obliged.
Thanks
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: change setHandlers XML::Parser
by Anonymous Monk on Oct 19, 2012 at 10:07 UTC | |
Re: change setHandlers XML::Parser
by Jenda (Abbot) on Oct 19, 2012 at 21:42 UTC | |
by etlamar (Novice) on Oct 20, 2012 at 00:27 UTC | |
by Jenda (Abbot) on Oct 20, 2012 at 09:00 UTC | |
by etlamar (Novice) on Oct 20, 2012 at 11:24 UTC | |
by etlamar (Novice) on Oct 20, 2012 at 14:13 UTC | |
by Anonymous Monk on Oct 20, 2012 at 00:52 UTC |
Back to
Seekers of Perl Wisdom