File: test-ids.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 (32 lines) | stat: -rw-r--r-- 739 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
#
# $Id: test-ids.pl,v 1.1 1999/05/26 15:42:16 kmacleod Exp $
#

# This example parses each doc on the command line and prints all of
# the IDs found in the doc, with their Perl hash references

use XML::Parser;
use XML::Parser::Grove;
use XML::Grove;
use XML::Grove::IDs;

my $doc;

my $id_maker = new XML::Grove::IDs;

foreach $doc (@ARGV) {
    print "---- $doc ----\n";

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

    my $ids = $grove->get_ids;
    my $id;
    foreach $id (sort keys %$ids) {
	# prints the id and the hash reference to the element, not
	# pretty but this is just a test.
	# printing paths would be cool.
	print "$id - $ids->{$id}\n";
    }
}