in reply to Re: Finding node with attribute XML::LibXML
in thread Finding node with attribute XML::LibXML
use warnings; use strict; use XML::Twig; my $xml=<<'XML'; <root> <ProductKey>99</ProductKey> <Volume VolumeCategory="L" MeasurementCategory="Real">0.063</Volume> <Volume VolumeCategory="L" MeasurementCategory="Real">0.098989</Volume +> <Volume VolumeCategory="cuft" MeasurementCategory="Real">2.2</Volume> </root> XML my @vol_cat_L; my $twig= new XML::Twig( twig_handlers => { '/root/Volume[@VolumeCate +gory="L"]' => sub {push @vol_cat_L, $_}, }, ); $twig->parse( $xml); print "Number of L volume category: ",scalar @vol_cat_L,"\n"; ##OUTPUT (note the line in example data added by me): Number of L volume category: 2
|
|---|