-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwig.pl
More file actions
54 lines (45 loc) · 1.37 KB
/
twig.pl
File metadata and controls
54 lines (45 loc) · 1.37 KB
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
#!/usr/bin/perl -w
use strict;
use XML::Twig;
use XML::Parser;
use XML::SemanticDiff;
use Data::Dumper;
#my $twig = new XML::Twig(twig_handlers =>
# {player => \&player});
my $t= XML::Twig->new(
# the twig will include just the root and selected titles
twig_roots => { 'References/Party/PartyName' => \&print_n_purge
}
);
$t->parsefile( 'KY.xml');
sub print_n_purge
{
my( $t, $elt)= @_;
my $type = $elt->att('type');
print "$type"."\n";
my $id = $elt->att('id');
print "$id"."\n";
my $kind = $elt->att('kind');
print "$kind"."\n";
#print $elt->text; print the text (including sub-element texts)
# foreach my $primary ( $elt -> first_child ( 'PartyName' ) -> first_child ('Property') -> children() )
# {
# my $kind = $primary -> att ( 'kind' );
# print $kind;
### here you have the information you need to do the rest of your processing.
# }
$t->purge; # frees the memory
}
#my $root = $twig->root;
#$root->print;
#my %players = $root->children;
#print Dumper %players;
#foreach my $key (keys \%players)
{
#print "$key->{pcdata}";
}
#sub player
# {
# my ($twig, $player) = @_;
# print Dumper $twig;
# }