annotate Lib/IMPL/DOM/XMLReader.pm @ 11:75980091813b

DOM и навигация
author Sergey
date Wed, 02 Sep 2009 17:47:44 +0400
parents 63f6653b094e
children bb8d67f811ea
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
11
75980091813b DOM и навигация
Sergey
parents: 10
diff changeset
32 $this->{$_current} = $this->Navigator->NavigateCreate($element,%attrs);
10
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;