/usr/share/doc/libxml-grove-perl/examples/grove.pl is in libxml-grove-perl 0.46alpha-12.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | #
# Copyright (C) 1998 Ken MacLeod
# See the file COPYING for distribution terms.
#
# $Id: grove.pl,v 1.4 1999/05/06 23:13:02 kmacleod Exp $
#
use XML::Parser::PerlSAX;
use XML::Grove;
use XML::Grove::Builder;
my $builder = XML::Grove::Builder->new;
my $parser = XML::Parser::PerlSAX->new(Handler => $builder);
my $doc;
foreach $doc (@ARGV) {
my $grove = $parser->parse (Source => { SystemId => $doc });
dump_grove ($grove);
}
sub dump_grove {
my $grove = shift;
my @context = ();
_dump_contents ($grove->{Contents}, \@context);
}
sub _dump_contents {
my $contents = shift;
my $context = shift;
foreach $item (@$contents) {
if (ref ($item) =~ /::Element/) {
push @$context, $item->{Name};
my @attributes = %{$item->{Attributes}};
print STDERR "@$context \\\\ (@attributes)\n";
_dump_contents ($item->{Contents}, $context);
print STDERR "@$context //\n";
pop @$context;
} elsif (ref ($item) =~ /::PI/) {
my $target = $item->{Target};
my $data = $item->{Data};
print STDERR "@$context ?? $target($data)\n";
} elsif (ref ($item) =~ /::Characters/) {
my $data = $item->{Data};
$data =~ s/([\x80-\xff])/sprintf "#x%X;", ord $1/eg;
$data =~ s/([\t\n])/sprintf "#%d;", ord $1/eg;
print STDERR "@$context || $data\n";
} elsif (!ref ($item)) {
print STDERR "@$context !! SCALAR: $item\n";
} else {
print STDERR "@$context !! OTHER: $item\n";
}
}
}
|