On Thu, 29 Jul 2004, Abhishek Dave wrote:
> Hello All,
> i am new to use XML::Parser module and i want to start with some simple program .
> Any one , who knows how to use this module.
> any helpful sample codes.
>
> Thanks in Advance.
> Abhishek
I've started to use it recently. Read "man XML::Parser", or find the
module on CPAN. Here is some sample code (it should but may not work
since I am going to modify the actual code that does work):
use XML::Parser;
my $p;
#$p = new XML::Parser(Style => 'Debug');
$p = new XML::Parser(Style => 'Subs');
$input = "<table width=100><tr><td> Some sample input</td></tr></table>";
# This is how to use styel Subs:
sub table {
my [EMAIL PROTECTED];
$width = $p{width};
print "This is done when <table> is found. Width=$width\n";
}
sub table_ { print "Done when </table>\n" }
# you can run similar functios for tr and tr_... but the code will not
# fail if you don't define them
# This will handle the suff between tags:
$p->setHandlers(Char => sub { $Collect .= $_[1] });
# you could say something like:
# $p->setHandlers(Char => &f);
# if you define sub f
#Finally:
$p->parse($input);
## Vlado