use strict; use XML::Twig; my $file = "bin/Example.xml"; my $node = $ARGV[0]; my $value = $ARGV[1]; my $i = 0; my $twig= new XML::Twig( twig_handlers => { Record => \&Record }); $twig->parsefile($file); print "Finished Search!\n"; sub Record { my( $twig, $record)= @_; my @matcharray= $record->get_xpath($node); for my $match (@matcharray[-1]){ if( $match->text eq $value){ # PRINT ALL NODES FROM THIS RECORD HERE... }} $twig->purge; } #### use strict; use XML::Twig; my $file = "bin/Example.xml"; my $node = $ARGV[0]; my $value = $ARGV[1]; my $count = 0; open(INDEX, ">bin/Index.txt"); my $twig = XML::Twig->new( start_tag_handlers => { Record => \&Count }, twig_roots => { $node => \&Record } ); $twig->parsefile($file); $twig->purge; sub Count { my ( $twig, $element )=@_; $count++; $twig->purge;} sub Record { my ( $twig, $record )=@_; if($record->text eq $value) { print INDEX $count."\n"; } $twig->purge; } #### use strict; use XML::Twig; my $file = "bin/Example.xml"; my $i; my $count = 0; my $data_file = "bin/Index.txt"; open(DAT, $data_file) || die("Could not open file!"); my @id=; close(DAT); my $twig = XML::Twig->new( start_tag_handlers => { Record => \&Check }, twig_handlers => { Record => \&Process } ); $twig->parsefile($file); $twig->purge; sub Check { my ($twig, $record)=@_; $i = 0; $count++; if ($count > $id[-1]){ $twig->finish_now;} my $thisId = $count."\n"; foreach my $id (@id){ if ($thisId eq $id){ $i = 1; last;}} if ( $i ne 1){ $record->ignore; } } sub Process { my ($twig, $record)=@_; # PRINT ALL NODES FROM RECORD HERE... $twig->purge; } #### Title 1<\Title> <Year>2007<\Year> <Author>W. T. Wright<\Author> <Copyright> <Year>2006<\Year> <Number>A84LEU<\Number> <\Copyright> … <Info>Blah Blah Blah<\Info> <\Record> … <Record id="429000"> <Title>Title 999<\Title> <Year>2004<\Year> <Author>A. R. Smith<\Author> <Copyright> <Year>2003<\Year> <Number>D93YAK<\Number> <\Copyright> … <Info>Halb Halb Halb<\Info> <\Record> <\Root>