Re: Trying to parse XML file
by Richard Jolly other posts by this author
Aug 23 2004 2:56PM messages near this date
view in the new Beta List Site
Trying to parse XML file
|
RE: New Module? CPAN?
& XSLT 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
Thread:
Kevin Old
Richard Jolly
|