Emanuel has asked for the wisdom of the Perl Monks concerning the following question:
the code i use to parse the XML is the following:<Item> <Phone_no>123456789</Phone_no> <Content>Message Sent</Content> </Item> <Item> <Phone_no>12345</Phone_no> <Content>Error: Incorrect phone number</Content> </Item> </Packet>
the script breaks after calling $parser->parse($xml)..sub parse_return_xml { logger("DEBUG","Sub Parse Return XML"); my $message; my $i=0; my @phone; my @content; my @bad; my $xml = @_; logger("DEBUG","$xml"); logger("DEBUG","Creating XML::Parser Object"); my $parser = new XML::Parser(Handlers => { Start => \&start_tag, End => \&end_tag, Char => \&do_char }); $parser->parse($xml); sub start_tag { logger("DEBUG","start_tag"); my ($p, $elt, %atts) = @_; return unless $elt eq 'Content' || $elt eq 'Phone_no'; $atts{'_str'} = ''; $message = \%atts; } sub end_tag { logger("DEBUG","end_tag"); my ($p, $elt) = @_; format_message($message) if ($elt eq 'Content' || $elt + eq 'Phone_no') && $message; } sub do_char { logger("DEBUG","do_char"); my ($p, $str) = @_; $message->{'_str'} .= $str; } sub format_message { logger("DEBUG","Sub Format_message"); logger("DEBUG","\$i = $i"); my $atts = shift; logger("DEBUG",$atts->{'_str'}); if ($atts->{'_str'} =~ /err/i) { $bad[$i] = $phone[$i]; } else { $bad[$i] = 'holymoly'; } if ($atts->{'_str'} =~ /[0..9]/) { $phone[$i] = $atts->{'_str'}; } if ($atts->{'_str'} =~ /[a..zA..Z]/) { $content[$i] = $atts->{'_str'}; $i++; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XML::Parser and Subs in a sub
by Emanuel (Pilgrim) on Oct 03, 2001 at 06:47 UTC | |
|
Re: XML::Parser and Subs in a sub
by mirod (Canon) on Oct 03, 2001 at 11:39 UTC | |
|
Re: XML::Parser and Subs in a sub
by Fletch (Bishop) on Oct 03, 2001 at 06:22 UTC | |
|
Re: XML::Parser and Subs in a sub
by jerrygarciuh (Curate) on Oct 03, 2001 at 06:19 UTC | |
by Emanuel (Pilgrim) on Oct 03, 2001 at 06:25 UTC |