Mercurial > pub > Impl
diff Lib/IMPL/DOM/Schema/NodeSet.pm @ 7:94d47b388442
Улучшены тесты
Исправлены ошибки
Улучшена документация
Работа над схемой DOM
author | Sergey |
---|---|
date | Mon, 24 Aug 2009 01:05:34 +0400 |
parents | |
children | 1ca530e5c9c5 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/IMPL/DOM/Schema/NodeSet.pm Mon Aug 24 01:05:34 2009 +0400 @@ -0,0 +1,71 @@ +package IMPL::DOM::Schema::NodeSet; +use strict; +use warnings; + +use base qw(IMPL::DOM::Schema::Item); +use IMPL::Class::Property; + +BEGIN { + public property UnexpectedMessage => prop_all; + public property MaxMessage => prop_all; + public property MinMessage => prop_all; +} + +sub Validate { + my ($this,$node) = @_; + + my @errors; + + my %nodes = map { + $_->nodeName , + {Schema => $_, Min => $_->minOccur, Max => $_->maxOccur, Seen => 0 } + } @{$this->childNodes}; + + foreach my $child ( @{$node->childNodes} ) { + if (my $info = $nodes{$child->nodeName}) { + $info->{Seen}++; + push @errors,{ + Error => 1, + Source => $this, + Node => $child, + Message => $this->MaxMessage + } if ($info->{Seen} > $info->{Max}); + + push @errors,$info->{Schema}->Validate($child); + } else { + push @errors, { + Error => 1, + Source => $this, + Node => $child, + Message => $this->UnexpectedMessage + } + } + } + + foreach my $info (values %nodes) { + push @errors, { + Error => 1, + Source => $this, + Message => $this->MinMessage + } if $info->{Min} > $info->{Seen}; + } + + return @errors; +} + +1; + +__END__ + +=pod + +=head1 DESCRIPTION + + . . + C<IMPL::DOM::Schema::ComplexNode> C<IMPL::DOM::Schema::SimpleNode>. + + , + , + . + +=cut