while ($input =~ /<\/xnm:error>(?:\s*<output>)/) {
# Add any 'output' tags to the <xnm:error> mix
$input =~ s/(.*?)(<\/xnm:error>)(?:\s*(<output>.*?<\/output>\s*))(.*)/$1$3$2$4/s;
}
# Catch bad XML
eval {
$parser->parse_more($input);
};
if ($@) {
my($col) = $@ =~ /column (\d+)/;
my($error) = $@ =~ /^(.*?)\s+at/m;
my $mismatched = $error =~ /mismatched/;
# Check out the previous 50 characters
my $bad_area = substr $self->{sofar}, $col-50;
print "Something bad has happened - XML got garbled.\n";
print "Here's what it did not like:\n\t",$bad_area,"\n";
print "The error was: $error\n";
print "This tag doesn't has a start tag!\n" if $mismatched;
die "Parse failure";
}
$parser->parse_done if ($done);
$done;
}
#
# Mark the end of parsing, normally caused by end-of-file
#
sub parse_done
{
tracept("Parse");
my($self, $input) = @_;
my $done = $self->parse_more($input) if ($input);
return if $done;
my $parser = $self->{JUNOS_Parser};
$parser->parse_done;
}
#
# Destory the parser and clean up the self-referential nature of the objects.
sub parse_destroy
{
my ($self) = @_;
my $parser = $self->{JUNOS_Parser};
$parser->{JUNOS_Device} = undef;
$self->{JUNOS_Parser} = undef;
undef $parser;
}
#
# These functions interact with the DOM parser. In order to pull
# complete DOM objects from the DOM parser, we need to reinitialize
# it before each <rpc-reply> and terminate it after each </rpc-reply>.
#
#
# Open a reply by reinitializing the DOM parser, passing it
# the information we learned at connection startup.
#
sub openReply
{
tracept("Reply");
my($self, $parser) = @_;
XML::Parser::Dom::Init($parser);
XML::Parser::Dom::XMLDecl($parser, $self->{XMLDecl_Version},
$self->{XMLDecl_Encoding}, $self->{XMLDecl_Standalone});
$self->{JUNOS_expect_1st_element} = 1;
undef $self->{tag};
}
#
# Close a reply by terminating the parser and passing back the DOM
# document that it returned to us.
sub closeReply
{
tracept("Reply");
my($self, $parser) = @_;
my $reply = XML::Parser::Dom::Final($parser);
return $reply;
}
sub clear_errors
{
my($self) = @_;
$self->{Errors} = [];
return 1;
}
sub report_error
{
=5= |