10
|
1 package IMPL::DOM::XMLReader;
|
|
2 use strict;
|
|
3 use warnings;
|
|
4
|
|
5 use base qw(IMPL::Object IMPL::Object::Autofill);
|
|
6 use IMPL::Class::Property;
|
|
7 use IMPL::Class::Property::Direct;
|
|
8 use XML::Parser;
|
|
9
|
14
|
10 __PACKAGE__->PassThroughArgs;
|
|
11
|
10
|
12 BEGIN {
|
|
13 public _direct property Navigator => prop_get | owner_set;
|
|
14 private _direct property _current => prop_all;
|
|
15 }
|
|
16
|
|
17 sub Parse {
|
|
18 my ($this,$in) = @_;
|
|
19
|
|
20 my $parser = new XML::Parser(
|
|
21 Handlers => {
|
|
22 Start => sub {shift; goto &OnStart($this,@_)},
|
|
23 End => sub {shift; goto &OnEnd($this,@_)},
|
|
24 Char => sub {shift; goto &OnChar($this,@_)}
|
|
25 }
|
|
26 );
|
|
27
|
|
28 $parser->parse($in);
|
|
29 }
|
|
30
|
12
|
31 sub ParseFile {
|
|
32 my ($this,$in) = @_;
|
|
33
|
|
34 my $parser = new XML::Parser(
|
|
35 Handlers => {
|
14
|
36 Start => sub {shift; goto &_OnStart($this,@_)},
|
|
37 End => sub {shift; goto &_OnEnd($this,@_)},
|
|
38 Char => sub {shift; goto &_OnChar($this,@_)}
|
12
|
39 }
|
|
40 );
|
|
41
|
|
42 $parser->parsefile($in);
|
|
43 }
|
|
44
|
|
45
|
14
|
46 sub _OnBegin {
|
10
|
47 my ($this,$element,%attrs) = @_;
|
|
48
|
11
|
49 $this->{$_current} = $this->Navigator->NavigateCreate($element,%attrs);
|
10
|
50 }
|
|
51
|
14
|
52 sub _OnEnd {
|
10
|
53 my ($this,$element) = @_;
|
|
54
|
|
55 $this->{$_current} = $this->Back;
|
|
56 }
|
|
57
|
14
|
58 sub _OnChar {
|
10
|
59 my ($this,$val) = @_;
|
|
60
|
|
61 $this->{$_current}->nodeValue($this->{$_current}->nodeValue . $val);
|
|
62 }
|
|
63
|
|
64 1;
|
12
|
65
|
|
66 __END__
|
|
67
|
|
68 =pod
|
|
69
|
|
70 =head1 SYNOPSIS
|
|
71
|
|
72 my $reader = new IMPL::DOM::XMLReader(Navigator => $DomBuilder);
|
|
73 my $obj = $reader->parsefile("data.xml");
|
|
74
|
14
|
75 =head1 DESCRIPTION
|
12
|
76
|
|
77 , .
|
|
78 .
|
|
79
|
|
80 C<NavigateCreate> C<Back>
|
|
81
|
14
|
82 =head1 METHODS
|
|
83
|
|
84 =over
|
|
85
|
|
86 =item C<CTOR(Naviagtor => $builder)>
|
|
87
|
|
88 ,
|
|
89
|
|
90 =item C<$obj->Parse($in)>
|
|
91
|
|
92 . xml , HANDLE.
|
|
93
|
|
94 =item C<$obj->ParseFile($fileName)>
|
|
95
|
|
96 C<$fileName>.
|
|
97
|
|
98 =back
|
|
99
|
12
|
100 =cut
|