On 23 Aug 2004, at 20:29, Kevin Old wrote:
Hello everyone,
I'm new to parsing XML files. I've got a somewhat working attempt, but keep getting errors when certain elements are undefined.
Can't call method "as_text" on an undefined value at ./xmltreebuild.pl line 33.
Believe the error message! Line 33 is:
$tmp[11] = $prod->find_by_tag_name('runtime')->as_text;So the find_by_tag_name is returning undef, rather than an object that has an as_text method. Its not finding runtime, because in the xml its spelled run-time.
But if you may or may not find a match, you'll have to check:
if ( $elem = $prod->find_by_tag_name('run-time') ) {
$tpm[11] = $elem->as_text;
}EasyTree or another package may give you a nicer way of doing this that lots of conditionals in your code.
Richard
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
