Parsing w/XML::Twig & Perl
by Mike Blezien other posts by this author
Jul 21 2007 4:14AM messages near this date
view in the new Beta List Site
Re: IRI support in a CPAN lib
|
RE: Parsing w/XML::Twig & Perl
& XSLT Hello,
we've run a few test and everything seems to be working as expected, but got one
little problem I haven't been able to figure out, why we keep getting this error
(code snipt below)
----
Can't call method "first_child_text" on an undefined value
at .. /sample.cgi line 56 which is this line "my $tracknums =
$tracks-> first_child_text('number_of_tracks');
----
a value for the "$tracknums" is returned and all other values are returned as
expected
after it parses the XML file. Haven't been able to figure out why I keep getting
this error??
############################################################################
my $twig = new XML::Twig(twig_handlers => { product => \&get_products });
$twig-> parsefile("$xmlfile"); $twig->purge();
############################################################################
sub get_products {
my($t,$elt) = @_;
my($track_title,$trackno,$setno,$soundtype,$codec,$file);
# process each product loop.
my $article_number = $elt-> first_child_text('article_number');
my $dist_number = $elt-> first_child_text('distributor_number');
my $dist_name = $elt-> first_child_text('distributor_name');
my $artist = $elt-> first_child_text('artist');
my $ean_upc = $elt-> first_child_text('ean_upc');
my $set_total = $elt-> first_child_text('set_total');
my $tracks = $elt-> first_child('tracks');
# LINE 56 here
my $tracknums = $tracks-> first_child_text('number_of_tracks');
return unless $tracks;
for my $track ($tracks-> children('track'))
{
$track_title = $track-> first_child_text('title');
$trackno = $track-> first_child_text('trackno');
$setno = $track-> first_child_text('setno');
for my $sound ($track-> children('sound'))
{
$soundtype = $sound-> first_child_text('sound_type');
$codec = $sound-> first_child_text('codec');
$file = $sound-> first_child_text('file');~;
}
} # close for $track loop
# free up memory
$t-> purge();
}
Mike(mickalo)Blezien
===============================
Thunder Rain Internet Publishing
Providing Internet Solution that Work
===============================
_______________________________________________
Perl-XML mailing list
Perl-XML@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Mike Blezien
Forrest Cahoon
Mike Blezien
|