
johnMc
New User
Oct 24, 2011, 7:04 AM
Post #1 of 1
(282 views)
|
|
XML Parsing Issue help needed please.
|
Can't Post
|
|
Hi folks. I have this piece of code which is causing me a few headaches. I have marked what would be LINE 105 (as according to the error at the end......). It does parse everything else. I just cannot work out why this line 105 is a problem.
sub readProcessFile { my $self = shift; my $doc; my $file = shift; #my $content; if(-e "$self->{PROCESSDIR}/$file"){ my $parser = new XML::DOM::Parser; $doc = $parser->parsefile("$self->{PROCESSDIR}/$file"); if(! $doc){ return 0; } my $processes = $doc->getElementsByTagName('process'); my $n = $processes->getLength(); my @processes_array = (); #read all processes for(my $i=0;$i <$n ; $i++){ my %process_data = undef; my $process = $processes->item($i); my $process_attr = $process->getAttributes(); my $procid = $process_attr->getNamedItem("id"); $process_data{"id"} = $procid->getValue; $process_data{"profile"} = "default"; if($process_attr->getNamedItem("profile")){ $process_data{"profile"} = $process_attr->getNamedItem("profile")->getValue; } if($process->hasChildNodes()){ #read process parameters for my $parameter ($process->getChildNodes){ -LINE-105- my $tag_name = $parameter->getTagName(); # get file by tag Name if(lc($tag_name) eq "file"){ $process_data{$tag_name} = $parameter->getFirstChild->toString(); next; } #get parameters elsif(lc($tag_name) eq "parameter"){ my $param_name = $parameter->getAttribute("name") || undef; if($parameter->getFirstChild && defined($param_name)){ $process_data{$param_name} = $parameter->getFirstChild->toString(); } } } } if(%process_data){ push(@processes_array,\%process_data); } } return @processes_array; } return 0; } Here is the XML to parse:
<ffencoderd><process id="1"> <file>IAmLegend-Trailer.mp4</file> <profile>default</profile> </process> </ffencoderd> I get this error: 2011-10-24 14:38:16 : Can't locate object method "getTagName" via package "XML::DOM::Text" at /scratch/ffencoderd/ffencoderd/Queue.pm line 105. If I remove the <file></file> in the XML file then the file is parsed ok but as expected nothing will happen :) Can any of you PERL genius'es spot the issue please? Many thanks.
(This post was edited by johnMc on Oct 24, 2011, 7:17 AM)
|