For this XML::Twig can be used.
In below code, input date is given via command line.
you can get the mindrybulb value also just by adding some more code in the handler part.
use XML::Twig; undef $/; my $date=$ARGV[0]; my $s=<DATA>; my (@max,@min); my $t=new XML::Twig( twig_handlers=>{ "AnnualWeatherRecord"=>sub{my ($c)=$_[1]->get_xpath("//DailyWeather +Record/date[string()=\"$date\"]/../temperature/maxdrybulb[\@number]") +; push @max,[$date,$c->att("number")] if (defined $c and defined $c->att +("number"))} } ); $t->parse($s); local $"="\n"; print @$_ for @max; __DATA__ <AnnualWeatherRecord> <DailyWeatherRecord> <date>1-1-2004</date> <temperature> <maxdrybulb unit="degrees-centigrade" number="30.95"/> <mindrybulb unit="degrees-centigrade" number="30.95"/> <maxwetbulb unit="degrees-centigrade" number="33.53"/> <minwetbulb unit="degrees-centigrade" number="30.53"/> </temperature> <totalrainfall unit="mm" number="0.5"/> </DailyWeatherRecord> </AnnualWeatherRecord>
In reply to Re: Help with XML::XPath
by murugu
in thread Help with XML::XPath
by perl_seeker
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |