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>
2007<\Year>
W. T. Wright<\Author>
2006<\Year>
A84LEU<\Number>
<\Copyright>
…
Blah Blah Blah<\Info>
<\Record>
…
Title 999<\Title>
2004<\Year>
A. R. Smith<\Author>
2003<\Year>
D93YAK<\Number>
<\Copyright>
…
Halb Halb Halb<\Info>
<\Record>
<\Root>