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

DOM
author Sergey
date Fri, 28 Aug 2009 16:26:20 +0400
parents
children 75980091813b 955b2324c1bf
comparison
equal deleted inserted replaced
9:5899df8c289e 10:63f6653b094e
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
29 sub OnBegin {
30 my ($this,$element,%attrs) = @_;
31
32 $this->{$_current} = $this->Navigator->CreateAndNavigate($element,%attrs);
33 }
34
35 sub OnEnd {
36 my ($this,$element) = @_;
37
38 $this->{$_current} = $this->Back;
39 }
40
41 sub OnChar {
42 my ($this,$val) = @_;
43
44 $this->{$_current}->nodeValue($this->{$_current}->nodeValue . $val);
45 }
46
47 1;