diff Lib/IMPL/DOM/Schema/NodeList.pm @ 125:a4b0a819bbda

Small fixes in IMPL::DOM::Schema
author wizard
date Thu, 10 Jun 2010 17:43:51 +0400
parents cf3b6ef2be22
children 1e7f03414b65
line wrap: on
line diff
--- a/Lib/IMPL/DOM/Schema/NodeList.pm	Thu Jun 10 02:45:59 2010 +0400
+++ b/Lib/IMPL/DOM/Schema/NodeList.pm	Thu Jun 10 17:43:51 2010 +0400
@@ -23,13 +23,14 @@
 }
 
 sub Validate {
-    my ($this,$node) = @_;
+    my ($this,$node,$ctx) = @_;
     
     my @nodes = map {
         {nodeName => $_->name, anyNode => $_->isa('IMPL::DOM::Schema::AnyNode') , Schema => $_, Max => $_->maxOccur eq 'unbounded' ? undef : $_->maxOccur, Min => $_->minOccur, Seen => 0 }
     } @{$this->childNodes};
     
     my $info = shift @nodes;
+    my $sourceSchema = $ctx->{Source} || $this->parentNode;
     
     foreach my $child ( @{$node->childNodes} ) {
         #skip schema elements
@@ -40,7 +41,7 @@
                 Node => $child,
                 Parent => $node,
                 Schema => $info->{Schema},
-                Source => $this
+                Source => $sourceSchema
             ) if $info->{Min} > $info->{Seen};
             
             $info = shift @nodes;
@@ -51,7 +52,7 @@
             Message => $this->messageUnexpected,
             Node => $child,
             Parent => $node,
-            Source => $this
+            Source => $sourceSchema
         ) unless $info;
         
         # it's ok, we found schema element for child
@@ -74,7 +75,7 @@
             Message => $this->messageUnexpected,
             Node => $child,
             Parent => $node,
-            Source => $this,
+            Source => $sourceSchema,
         ) if $info->{Max} and $info->{Seen} > $info->{Max};
     }
     
@@ -83,7 +84,7 @@
         return new IMPL::DOM::Schema::ValidationError (
             Error => 1,
             Message => $this->messageNodesRequired,
-            Source => $this,
+            Source => $sourceSchema,
             Parent => $node,
             Schema => $info->{Schema}
         ) if $info->{Seen} < $info->{Min};