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
|
|
10 BEGIN {
|
|
11 public _direct property Navigator => prop_get | owner_set;
|
|
12 private _direct property _current => prop_all;
|
|
13 }
|
|
14
|
|
15 sub Parse {
|
|
16 my ($this,$in) = @_;
|
|
17
|
|
18 my $parser = new XML::Parser(
|
|
19 Handlers => {
|
|
20 Start => sub {shift; goto &OnStart($this,@_)},
|
|
21 End => sub {shift; goto &OnEnd($this,@_)},
|
|
22 Char => sub {shift; goto &OnChar($this,@_)}
|
|
23 }
|
|
24 );
|
|
25
|
|
26 $parser->parse($in);
|
|
27 }
|
|
28
|
12
|
29 sub ParseFile {
|
|
30 my ($this,$in) = @_;
|
|
31
|
|
32 my $parser = new XML::Parser(
|
|
33 Handlers => {
|
|
34 Start => sub {shift; goto &OnStart($this,@_)},
|
|
35 End => sub {shift; goto &OnEnd($this,@_)},
|
|
36 Char => sub {shift; goto &OnChar($this,@_)}
|
|
37 }
|
|
38 );
|
|
39
|
|
40 $parser->parsefile($in);
|
|
41 }
|
|
42
|
|
43
|
10
|
44 sub OnBegin {
|
|
45 my ($this,$element,%attrs) = @_;
|
|
46
|
11
|
47 $this->{$_current} = $this->Navigator->NavigateCreate($element,%attrs);
|
10
|
48 }
|
|
49
|
|
50 sub OnEnd {
|
|
51 my ($this,$element) = @_;
|
|
52
|
|
53 $this->{$_current} = $this->Back;
|
|
54 }
|
|
55
|
|
56 sub OnChar {
|
|
57 my ($this,$val) = @_;
|
|
58
|
|
59 $this->{$_current}->nodeValue($this->{$_current}->nodeValue . $val);
|
|
60 }
|
|
61
|
|
62 1;
|
12
|
63
|
|
64 __END__
|
|
65
|
|
66 =pod
|
|
67
|
|
68 =head1 SYNOPSIS
|
|
69
|
|
70 my $reader = new IMPL::DOM::XMLReader(Navigator => $DomBuilder);
|
|
71 my $obj = $reader->parsefile("data.xml");
|
|
72
|
|
73 =head2 DESCRIPTION
|
|
74
|
|
75 , .
|
|
76 .
|
|
77
|
|
78 C<NavigateCreate> C<Back>
|
|
79
|
|
80 =cut
|