Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML::Parser with no globals

Status
Not open for further replies.

vvhitekid2

Technical User
Jul 8, 2003
56
0
0
US
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::parser 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::parser->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-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top