in reply to Help with XML::XPath
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>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Help with XML::XPath
by mirod (Canon) on Aug 19, 2004 at 14:06 UTC |