On 19/03/2012 15:12, Anirban Adhikary wrote:
Hi,
When I am trying to print the value against the tag ALPHA it is not prints
anything,though it is not showing any warnings.
use strict;
use warnings;
use XML::Twig;
my $twig = XML::Twig->new(start_tag_handlers => {
BSC => \&on_BSC
});
sub on_BSC {
my($twig, $bsc)= @_;
print $bsc->id, "\n";
my $alpha = $bsc->field('ALPHA');
print $alpha, "\n";
$twig->purge;
}
$twig->parsefile(ISProducts.xml');
Hi List,
When I have changed the method
from my $twig = XML::Twig->new(start_tag_
handlers => {
BSC => \&on_BSC
});
to
my $twig = XML::Twig->new(TwigHandlers => {
BSC => \&on_BSC
});
I am able to print the value against the ALPHA tag.
Thanks to you for your support.
Hi Anirban
I suggested using start_tag_handlers because what you wanted to do was
extract the id attribute from the start tag of all <BSC> elements, so
there was no point in having any more of the element in store that just
that start tag. It is also more efficient
Changing to twig_handlers makes entirety of each "twig" (the <BSC>
element) available, so you are able to access the child elements as you
have found.
Rob
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/