vvhitekid2
Technical User
Here is the situation. I need to have a single function in a library parse an XML document and return the content. How can I do this with XML:
arser without using globals? I can have other functions, but I am unsure on how to pass the data to the Parse handlers.
For example (this wont work):
sub P_parse {
my $p1 = XML:
arser->new( Handlers => {
Init => \&handle_doc_start,
Final => \&handle_doc_end,
Start => \&handle_elem_start,
End => \&handle_elem_end,
Char => \&handle_char_data,
});
my $req = new HTTP::Request GET => $URL;
$ua->timeout(5);
my $res = $ua->request($req);
if ($res->is_success) {
my $content = $res->content;
$p1->parse($content);
}
}
###Handlers###
sub handle_doc_start {
$$vars{'output'} .= "<h1>Results</h1>\n";
}
... and so on with all the handlers...
Thanks in advance-
For example (this wont work):
sub P_parse {
my $p1 = XML:
Init => \&handle_doc_start,
Final => \&handle_doc_end,
Start => \&handle_elem_start,
End => \&handle_elem_end,
Char => \&handle_char_data,
});
my $req = new HTTP::Request GET => $URL;
$ua->timeout(5);
my $res = $ua->request($req);
if ($res->is_success) {
my $content = $res->content;
$p1->parse($content);
}
}
###Handlers###
sub handle_doc_start {
$$vars{'output'} .= "<h1>Results</h1>\n";
}
... and so on with all the handlers...
Thanks in advance-