File: test-sub.pl

package info (click to toggle)
libxml-grove-perl 0.46alpha-6
  • links: PTS
  • area: main
  • in suites: woody
  • size: 204 kB
  • ctags: 158
  • sloc: perl: 1,057; makefile: 34
file content (33 lines) | stat: -rw-r--r-- 660 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use XML::Parser;
use XML::Parser::Grove;
use XML::Grove;
use XML::Grove::Sub;

my $doc;

my $filter = new Sub;

foreach $doc (@ARGV) {
    my $parser = XML::Parser->new(Style => 'grove');
    $parser->parsefile ($doc);
    my $grove = $parser->{Grove};

    # this sub returns all the elements with a name containing the letter `d'.
    my $sub = sub {
	my ($object) = @_;

	if (ref($object) =~ /::Element/
	    && $object->{Name} =~ /d/i) {
	    return ($object);
	}

	return ();
    };
	    
    my @matches = $grove->filter($sub);
    my $match;
    foreach $match (@matches) {
	# prints the element name of the match.
	print $match->{Name} . "\n";
    }
}