Mercurial > pub > Impl
view 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 |
line wrap: on
line source
package IMPL::DOM::XMLReader; use strict; use warnings; use base qw(IMPL::Object IMPL::Object::Autofill); use IMPL::Class::Property; use IMPL::Class::Property::Direct; use XML::Parser; BEGIN { public _direct property Navigator => prop_get | owner_set; private _direct property _current => prop_all; } sub Parse { my ($this,$in) = @_; my $parser = new XML::Parser( Handlers => { Start => sub {shift; goto &OnStart($this,@_)}, End => sub {shift; goto &OnEnd($this,@_)}, Char => sub {shift; goto &OnChar($this,@_)} } ); $parser->parse($in); } sub ParseFile { my ($this,$in) = @_; my $parser = new XML::Parser( Handlers => { Start => sub {shift; goto &OnStart($this,@_)}, End => sub {shift; goto &OnEnd($this,@_)}, Char => sub {shift; goto &OnChar($this,@_)} } ); $parser->parsefile($in); } sub OnBegin { my ($this,$element,%attrs) = @_; $this->{$_current} = $this->Navigator->NavigateCreate($element,%attrs); } sub OnEnd { my ($this,$element) = @_; $this->{$_current} = $this->Back; } sub OnChar { my ($this,$val) = @_; $this->{$_current}->nodeValue($this->{$_current}->nodeValue . $val); } 1; __END__ =pod =head1 SYNOPSIS my $reader = new IMPL::DOM::XMLReader(Navigator => $DomBuilder); my $obj = $reader->parsefile("data.xml"); =head2 DESCRIPTION Простой класс, использующий навигатор для постороения документа. В зависимости от используемого навигатора может быть получен различный результат. Навигатор должен поодерживать методы C<NavigateCreate> и C<Back> =cut