annotate Lib/IMPL/DOM/XMLReader.pm @ 10:63f6653b094e

DOM
author Sergey
date Fri, 28 Aug 2009 16:26:20 +0400
parents
children 75980091813b 955b2324c1bf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10
Sergey
parents:
diff changeset
1 package IMPL::DOM::XMLReader;
Sergey
parents:
diff changeset
2 use strict;
Sergey
parents:
diff changeset
3 use warnings;
Sergey
parents:
diff changeset
4
Sergey
parents:
diff changeset
5 use base qw(IMPL::Object IMPL::Object::Autofill);
Sergey
parents:
diff changeset
6 use IMPL::Class::Property;
Sergey
parents:
diff changeset
7 use IMPL::Class::Property::Direct;
Sergey
parents:
diff changeset
8 use XML::Parser;
Sergey
parents:
diff changeset
9
Sergey
parents:
diff changeset
10 BEGIN {
Sergey
parents:
diff changeset
11 public _direct property Navigator => prop_get | owner_set;
Sergey
parents:
diff changeset
12 private _direct property _current => prop_all;
Sergey
parents:
diff changeset
13 }
Sergey
parents:
diff changeset
14
Sergey
parents:
diff changeset
15 sub Parse {
Sergey
parents:
diff changeset
16 my ($this,$in) = @_;
Sergey
parents:
diff changeset
17
Sergey
parents:
diff changeset
18 my $parser = new XML::Parser(
Sergey
parents:
diff changeset
19 Handlers => {
Sergey
parents:
diff changeset
20 Start => sub {shift; goto &OnStart($this,@_)},
Sergey
parents:
diff changeset
21 End => sub {shift; goto &OnEnd($this,@_)},
Sergey
parents:
diff changeset
22 Char => sub {shift; goto &OnChar($this,@_)}
Sergey
parents:
diff changeset
23 }
Sergey
parents:
diff changeset
24 );
Sergey
parents:
diff changeset
25
Sergey
parents:
diff changeset
26 $parser->parse($in);
Sergey
parents:
diff changeset
27 }
Sergey
parents:
diff changeset
28
Sergey
parents:
diff changeset
29 sub OnBegin {
Sergey
parents:
diff changeset
30 my ($this,$element,%attrs) = @_;
Sergey
parents:
diff changeset
31
Sergey
parents:
diff changeset
32 $this->{$_current} = $this->Navigator->CreateAndNavigate($element,%attrs);
Sergey
parents:
diff changeset
33 }
Sergey
parents:
diff changeset
34
Sergey
parents:
diff changeset
35 sub OnEnd {
Sergey
parents:
diff changeset
36 my ($this,$element) = @_;
Sergey
parents:
diff changeset
37
Sergey
parents:
diff changeset
38 $this->{$_current} = $this->Back;
Sergey
parents:
diff changeset
39 }
Sergey
parents:
diff changeset
40
Sergey
parents:
diff changeset
41 sub OnChar {
Sergey
parents:
diff changeset
42 my ($this,$val) = @_;
Sergey
parents:
diff changeset
43
Sergey
parents:
diff changeset
44 $this->{$_current}->nodeValue($this->{$_current}->nodeValue . $val);
Sergey
parents:
diff changeset
45 }
Sergey
parents:
diff changeset
46
Sergey
parents:
diff changeset
47 1;