diff Lib/IMPL/DOM/Schema/Property.pm @ 103:c289ed9662ca

Schema beta 2 More strict validation, support for inflating a simple nodes and properties
author wizard
date Fri, 07 May 2010 18:17:40 +0400
parents d8dc6cad3f55
children 196bf443b5e1
line wrap: on
line diff
--- a/Lib/IMPL/DOM/Schema/Property.pm	Fri May 07 08:05:23 2010 +0400
+++ b/Lib/IMPL/DOM/Schema/Property.pm	Fri May 07 18:17:40 2010 +0400
@@ -34,21 +34,23 @@
 sub Validate {
     my ($this,$node) = @_;
     
-    if ($this->minOccur) {
-        my $prop = $this->name;
-        my $nodeProp = new IMPL::DOM::Node(nodeName => '::property', nodeValue => eval { $node->$prop() } || $node->nodeProperty($prop));
+    my $prop = $this->name;
+    
+    # buld a pseudo node for the property value 
+    my $nodeProp = new IMPL::DOM::Node(nodeName => '::property', nodeValue => eval { $node->$prop() } || $node->nodeProperty($prop));
         
-        if (! $nodeProp->nodeValue) {
-            return new IMPL::DOM::Schema::ValidationError(
-                Message => $this->RequiredMessage,
-                Node => $node,
-                Schema => $this
-            );
-        }
-        return $this->SUPER::Validate($nodeProp);
-    } else {
-        return ();
+    if ($nodeProp->nodeValue) {
+    	# we have a value so validate it
+    	return $this->SUPER::Validate($nodeProp);
+    } elsif($this->minOccur) {
+    	# we don't have a value but it's a mandatory property
+        return new IMPL::DOM::Schema::ValidationError(
+            Message => $this->RequiredMessage,
+            Node => $node,
+            Schema => $this
+        );
     }
+    
 }
 
 1;