1 |
dpavlin |
23 |
#!/usr/bin/perl |
2 |
|
|
|
3 |
|
|
use warnings; |
4 |
|
|
use strict; |
5 |
|
|
|
6 |
|
|
use XML::Rules; |
7 |
|
|
use File::Slurp; |
8 |
|
|
use Data::Dump qw/dump/; |
9 |
|
|
|
10 |
|
|
my $path = $ARGV[0] || 'protocol/inform.xml'; |
11 |
|
|
|
12 |
|
|
my $state; |
13 |
|
|
|
14 |
|
|
my $parser = XML::Rules->new( |
15 |
|
|
# start_rules => [ |
16 |
|
|
# '^division_name,fax' => 'skip', |
17 |
|
|
# ], |
18 |
|
|
namespaces => { |
19 |
|
|
'http://schemas.xmlsoap.org/soap/envelope/' => 'soapenv', |
20 |
|
|
'http://schemas.xmlsoap.org/soap/encoding/' => 'soap', |
21 |
|
|
'urn:dslforum-org:cwmp-1-0' => 'cwmp', |
22 |
|
|
}, |
23 |
|
|
rules => [ |
24 |
|
|
#_default => 'content trim', |
25 |
|
|
x_default => sub { |
26 |
|
|
my ($tag_name, $tag_hash, $context, $parent_data) = @_; |
27 |
|
|
warn dump( $tag_name, $tag_hash, $context ); |
28 |
|
|
}, |
29 |
|
|
qr/DeviceId/ => sub { |
30 |
|
|
my ($tag_name, $tag_hash, $context, $parent_data) = @_; |
31 |
|
|
$state->{ $tag_name } = $tag_hash; |
32 |
|
|
}, |
33 |
|
|
EventStruct => sub { |
34 |
|
|
my ($tag_name, $tag_hash, $context, $parent_data) = @_; |
35 |
|
|
push @{ $state->{ $tag_name } }, $tag_hash->{EventCode}->{_content}; |
36 |
|
|
}, |
37 |
|
|
MaxEnvelopes => sub { |
38 |
|
|
my ($tag_name, $tag_hash, $context, $parent_data) = @_; |
39 |
|
|
$state->{ $tag_name } = $tag_hash->{_content}; |
40 |
|
|
} |
41 |
|
|
] |
42 |
|
|
); |
43 |
|
|
|
44 |
|
|
my $xml = read_file( $path ); |
45 |
|
|
print "## $1 ##\n" if ( $xml =~ s/^Name:\s+(.*?)$//sm ); |
46 |
|
|
$xml =~ s/^.*Response:\s+//sm; |
47 |
|
|
warn $xml; |
48 |
|
|
$parser->parsestring( $xml ); |
49 |
|
|
|
50 |
|
|
print "state = ", dump( $state ); |