annotate Lib/IMPL/DOM/XMLReader.pm @ 20:267460284fb3

DOM Schema
author Sergey
date Tue, 22 Sep 2009 17:17:38 +0400
parents 65a7bb156fb7
children c2e7f7c96bcd
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
14
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
10 __PACKAGE__->PassThroughArgs;
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
11
10
Sergey
parents:
diff changeset
12 BEGIN {
Sergey
parents:
diff changeset
13 public _direct property Navigator => prop_get | owner_set;
Sergey
parents:
diff changeset
14 private _direct property _current => prop_all;
Sergey
parents:
diff changeset
15 }
Sergey
parents:
diff changeset
16
Sergey
parents:
diff changeset
17 sub Parse {
Sergey
parents:
diff changeset
18 my ($this,$in) = @_;
Sergey
parents:
diff changeset
19
Sergey
parents:
diff changeset
20 my $parser = new XML::Parser(
Sergey
parents:
diff changeset
21 Handlers => {
Sergey
parents:
diff changeset
22 Start => sub {shift; goto &OnStart($this,@_)},
Sergey
parents:
diff changeset
23 End => sub {shift; goto &OnEnd($this,@_)},
Sergey
parents:
diff changeset
24 Char => sub {shift; goto &OnChar($this,@_)}
Sergey
parents:
diff changeset
25 }
Sergey
parents:
diff changeset
26 );
Sergey
parents:
diff changeset
27
Sergey
parents:
diff changeset
28 $parser->parse($in);
Sergey
parents:
diff changeset
29 }
Sergey
parents:
diff changeset
30
12
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
31 sub ParseFile {
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
32 my ($this,$in) = @_;
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
33
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
34 my $parser = new XML::Parser(
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
35 Handlers => {
14
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
36 Start => sub {shift; goto &_OnStart($this,@_)},
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
37 End => sub {shift; goto &_OnEnd($this,@_)},
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
38 Char => sub {shift; goto &_OnChar($this,@_)}
12
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
39 }
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
40 );
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
41
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
42 $parser->parsefile($in);
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
43 }
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
44
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
45
14
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
46 sub _OnBegin {
10
Sergey
parents:
diff changeset
47 my ($this,$element,%attrs) = @_;
Sergey
parents:
diff changeset
48
11
75980091813b DOM и навигация
Sergey
parents: 10
diff changeset
49 $this->{$_current} = $this->Navigator->NavigateCreate($element,%attrs);
10
Sergey
parents:
diff changeset
50 }
Sergey
parents:
diff changeset
51
14
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
52 sub _OnEnd {
10
Sergey
parents:
diff changeset
53 my ($this,$element) = @_;
Sergey
parents:
diff changeset
54
Sergey
parents:
diff changeset
55 $this->{$_current} = $this->Back;
Sergey
parents:
diff changeset
56 }
Sergey
parents:
diff changeset
57
14
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
58 sub _OnChar {
10
Sergey
parents:
diff changeset
59 my ($this,$val) = @_;
Sergey
parents:
diff changeset
60
Sergey
parents:
diff changeset
61 $this->{$_current}->nodeValue($this->{$_current}->nodeValue . $val);
Sergey
parents:
diff changeset
62 }
Sergey
parents:
diff changeset
63
Sergey
parents:
diff changeset
64 1;
12
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
65
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
66 __END__
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
67
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
68 =pod
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
69
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
70 =head1 SYNOPSIS
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
71
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
72 my $reader = new IMPL::DOM::XMLReader(Navigator => $DomBuilder);
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
73 my $obj = $reader->parsefile("data.xml");
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
74
14
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
75 =head1 DESCRIPTION
12
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
76
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
77 , .
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
78 .
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
79
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
80 C<NavigateCreate> C<Back>
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
81
14
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
82 =head1 METHODS
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
83
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
84 =over
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
85
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
86 =item C<CTOR(Naviagtor => $builder)>
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
87
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
88 ,
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
89
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
90 =item C<$obj->Parse($in)>
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
91
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
92 . xml , HANDLE.
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
93
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
94 =item C<$obj->ParseFile($fileName)>
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
95
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
96 C<$fileName>.
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
97
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
98 =back
65a7bb156fb7 Дом модель и схема
Sergey
parents: 13
diff changeset
99
12
955b2324c1bf Работа над навигаторами и схемой DOM модели
Sergey
parents: 10
diff changeset
100 =cut