annotate Lib/IMPL/DOM/XMLReader.pm @ 13:bb8d67f811ea

merge heads
author Sergey
date Wed, 02 Sep 2009 23:11:14 +0400
parents 955b2324c1bf 75980091813b
children 65a7bb156fb7
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
12
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
29 sub ParseFile {
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
30 my ($this,$in) = @_;
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
31
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
32 my $parser = new XML::Parser(
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
33 Handlers => {
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
34 Start => sub {shift; goto &OnStart($this,@_)},
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
35 End => sub {shift; goto &OnEnd($this,@_)},
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
36 Char => sub {shift; goto &OnChar($this,@_)}
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
37 }
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
38 );
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
39
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
40 $parser->parsefile($in);
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
41 }
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
42
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
43
10
Sergey
parents:
diff changeset
44 sub OnBegin {
Sergey
parents:
diff changeset
45 my ($this,$element,%attrs) = @_;
Sergey
parents:
diff changeset
46
11
75980091813b DOM и навигация
Sergey
parents: 10
diff changeset
47 $this->{$_current} = $this->Navigator->NavigateCreate($element,%attrs);
10
Sergey
parents:
diff changeset
48 }
Sergey
parents:
diff changeset
49
Sergey
parents:
diff changeset
50 sub OnEnd {
Sergey
parents:
diff changeset
51 my ($this,$element) = @_;
Sergey
parents:
diff changeset
52
Sergey
parents:
diff changeset
53 $this->{$_current} = $this->Back;
Sergey
parents:
diff changeset
54 }
Sergey
parents:
diff changeset
55
Sergey
parents:
diff changeset
56 sub OnChar {
Sergey
parents:
diff changeset
57 my ($this,$val) = @_;
Sergey
parents:
diff changeset
58
Sergey
parents:
diff changeset
59 $this->{$_current}->nodeValue($this->{$_current}->nodeValue . $val);
Sergey
parents:
diff changeset
60 }
Sergey
parents:
diff changeset
61
Sergey
parents:
diff changeset
62 1;
12
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
63
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
64 __END__
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
65
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
66 =pod
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
67
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
68 =head1 SYNOPSIS
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
69
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
70 my $reader = new IMPL::DOM::XMLReader(Navigator => $DomBuilder);
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
71 my $obj = $reader->parsefile("data.xml");
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
72
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
73 =head2 DESCRIPTION
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
74
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
75 , .
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
76 .
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
77
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
78 C<NavigateCreate> C<Back>
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
79
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
80 =cut