diff Lib/IMPL/DOM/Schema.pm @ 20:267460284fb3

DOM Schema
author Sergey
date Tue, 22 Sep 2009 17:17:38 +0400
parents 1ca530e5c9c5
children fafe56cfcd69
line wrap: on
line diff
--- a/Lib/IMPL/DOM/Schema.pm	Fri Sep 11 16:30:39 2009 +0400
+++ b/Lib/IMPL/DOM/Schema.pm	Tue Sep 22 17:17:38 2009 +0400
@@ -34,7 +34,11 @@
 sub Validate {
     my ($this,$node) = @_;
     
-    #return IMPL::DOM::Schema::NodeSet->new()->appendRange(@{$this->childNodes})->Validate($node);
+    if ( my ($schemaNode) = $this->selectNodes(sub { $_[0]->name eq $node->nodeName })) {
+        $schemaNode->Validate($node);
+    } else {
+        return IMPL::DOM::Schema::VaidationError(Message=> "A specified document doesn't match the schema");
+    }
 }
 
 my $schema;
@@ -46,42 +50,42 @@
     $schema = new IMPL::DOM::Schema(nodeName => 'schema');
     
     $schema->appendRange(
-        IMPL::DOM::Schema::ComplexNode->new(nodeName => 'schema')->appendRange(
+        IMPL::DOM::Schema::ComplexNode->new(name => 'schema')->appendRange(
             IMPL::DOM::Schema::NodeSet->new()->appendRange(
-                IMPL::DOM::Schema::Node->new(nodeName => 'ComplexNode', type => 'ComplexNode', minOccur => 0, maxOccur=>'unbounded'),
-                IMPL::DOM::Schema::Node->new(nodeName => 'ComplexType', type => 'ComplexType', minOccur => 0, maxOccur=>'unbounded'),
-                IMPL::DOM::Schema::Node->new(nodeName => 'SimpleNode', type => 'SimpleNode', minOccur => 0, maxOccur=>'unbounded'),
-                IMPL::DOM::Schema::Node->new(nodeName => 'SimpleType', type => 'SimpleType', minOccur => 0, maxOccur=>'unbounded'),
-                IMPL::DOM::Schema::SimpleNode->new(nodeName => 'Node', minOccur => 0, maxOccur=>'unbounded'),
-                IMPL::DOM::Schema::SimpleNode->new(nodeName => 'Include', minOccur => 0, maxOccur=>'unbounded')
+                IMPL::DOM::Schema::Node->new(name => 'ComplexNode', type => 'ComplexNode', minOccur => 0, maxOccur=>'unbounded'),
+                IMPL::DOM::Schema::Node->new(name => 'ComplexType', type => 'ComplexType', minOccur => 0, maxOccur=>'unbounded'),
+                IMPL::DOM::Schema::Node->new(name => 'SimpleNode', type => 'SimpleNode', minOccur => 0, maxOccur=>'unbounded'),
+                IMPL::DOM::Schema::Node->new(name => 'SimpleType', type => 'SimpleType', minOccur => 0, maxOccur=>'unbounded'),
+                IMPL::DOM::Schema::SimpleNode->new(name => 'Node', minOccur => 0, maxOccur=>'unbounded'),
+                IMPL::DOM::Schema::SimpleNode->new(name => 'Include', minOccur => 0, maxOccur=>'unbounded')
             ),
         ),
         IMPL::DOM::Schema::ComplexType->new(type => 'NodeSet', nativeType => 'IMPL::DOM::Schema::NodeSet')->appendRange(
             IMPL::DOM::Schema::NodeSet->new()->appendRange(
-                IMPL::DOM::Schema::Node->new(nodeName => 'ComplexNode', type => 'ComplexNode', minOccur => 0, maxOccur=>'unbounded'),
-                IMPL::DOM::Schema::Node->new(nodeName => 'SimpleNode', type => 'SimpleNode', minOccur => 0, maxOccur=>'unbounded'),
-                IMPL::DOM::Schema::SimpleNode->new(nodeName => 'Node', minOccur => 0, maxOccur=>'unbounded'),
+                IMPL::DOM::Schema::Node->new(name => 'ComplexNode', type => 'ComplexNode', minOccur => 0, maxOccur=>'unbounded'),
+                IMPL::DOM::Schema::Node->new(name => 'SimpleNode', type => 'SimpleNode', minOccur => 0, maxOccur=>'unbounded'),
+                IMPL::DOM::Schema::SimpleNode->new(name => 'Node', minOccur => 0, maxOccur=>'unbounded'),
             )
         ),
         IMPL::DOM::Schema::ComplexType->new(type => 'NodeList', nativeType => 'IMPL::DOM::Schema::NodeList')->appendRange(
             IMPL::DOM::Schema::NodeSet->new()->appendRange(
-                IMPL::DOM::Schema::Node->new(nodeName => 'ComplexNode', type => 'ComplexNode', minOccur => 0, maxOccur=>'unbounded'),
-                IMPL::DOM::Schema::Node->new(nodeName => 'SimpleNode', type => 'SimpleNode', minOccur => 0, maxOccur=>'unbounded'),
-                IMPL::DOM::Schema::SimpleNode->new(nodeName => 'Node', minOccur => 0, maxOccur=>'unbounded'),
+                IMPL::DOM::Schema::Node->new(name => 'ComplexNode', type => 'ComplexNode', minOccur => 0, maxOccur=>'unbounded'),
+                IMPL::DOM::Schema::Node->new(name => 'SimpleNode', type => 'SimpleNode', minOccur => 0, maxOccur=>'unbounded'),
+                IMPL::DOM::Schema::SimpleNode->new(name => 'Node', minOccur => 0, maxOccur=>'unbounded'),
             )
         ),
         IMPL::DOM::Schema::ComplexType->new(type => 'ComplexType', nativeType => 'IMPL::DOM::Schema::ComplexType')->appendRange(
             IMPL::DOM::Schema::NodeList->new()->appendRange(
-                IMPL::DOM::Schema::Node->new(nodeName => 'NodeSet', minOccur => 0, type => 'NodeSet'),
-                IMPL::DOM::Schema::Node->new(nodeName => 'NodeList', minOccur => 0, type => 'NodeSet'),
-                IMPL::DOM::Schema::SimpleNode->new(nodeName => 'Node', minOccur => 0, maxOccur => 'unbounded')
+                IMPL::DOM::Schema::Node->new(name => 'NodeSet', minOccur => 0, type => 'NodeSet'),
+                IMPL::DOM::Schema::Node->new(name => 'NodeList', minOccur => 0, type => 'NodeSet'),
+                IMPL::DOM::Schema::SimpleNode->new(name => 'Node', minOccur => 0, maxOccur => 'unbounded')
             )
         ),
         IMPL::DOM::Schema::ComplexType->new(type => 'ComplexNode', nativeType => 'IMPL::DOM::Schema::ComplexNode')->appendRange(
             IMPL::DOM::Schema::NodeList->new()->appendRange(
-                IMPL::DOM::Schema::Node->new(nodeName => 'NodeSet', minOccur => 0, type => 'NodeSet'),
-                IMPL::DOM::Schema::Node->new(nodeName => 'NodeList', minOccur => 0, type => 'NodeSet'),
-                IMPL::DOM::Schema::SimpleNode->new(nodeName => 'Node', minOccur => 0, maxOccur => 'unbounded')
+                IMPL::DOM::Schema::Node->new(name => 'NodeSet', minOccur => 0, type => 'NodeSet'),
+                IMPL::DOM::Schema::Node->new(name => 'NodeList', minOccur => 0, type => 'NodeSet'),
+                IMPL::DOM::Schema::SimpleNode->new(name => 'Node', minOccur => 0, maxOccur => 'unbounded')
             )
         ),
         IMPL::DOM::Schema::ComplexType->new(type => 'SimpleType', nativeType => 'IMPL::DOM::Schema::SimpleType')->appendRange(
@@ -125,43 +129,48 @@
 
 =back
 
+=head1 DESCRIPTION
+
+DOM схема - это документ, состоящий из определенных узлов, описывающая структуру
+других документов.
+
 =head1 META SCHEMA
 
 Схема для описания схемы, эта схема используется для постороения других схем
 
 <schema>
-    <ComplexNode nodeName="schema">
+    <ComplexNode name="schema">
         <NodeSet>
-            <Node minOcuur="0" maxOccur="unbounded" nodeName="ComplexNode" type="ComplexNode"/>
-            <Node minOcuur="0" maxOccur="unbounded" nodeName="SimpleNode" type="SimpleNode"/>
-            <Node minOcuur="0" maxOccur="unbounded" nodeName="ComplexType" type="ComplexType"/>
-            <Node minOcuur="0" maxOccur="unbounded" nodeName="SimpleType" type="SimpleType"/>
-            <SimpleNode minOcuur="0" maxOccur="unbounded" nodeName="Node"/>
-            <SimpleNode minOcuur="0" maxOccur="unbounded" nodeName="Include"/>
+            <Node minOcuur="0" maxOccur="unbounded" name="ComplexNode" type="ComplexNode"/>
+            <Node minOcuur="0" maxOccur="unbounded" name="SimpleNode" type="SimpleNode"/>
+            <Node minOcuur="0" maxOccur="unbounded" name="ComplexType" type="ComplexType"/>
+            <Node minOcuur="0" maxOccur="unbounded" name="SimpleType" type="SimpleType"/>
+            <SimpleNode minOcuur="0" maxOccur="unbounded" name="Node"/>
+            <SimpleNode minOcuur="0" maxOccur="unbounded" name="Include"/>
         </NodeSet>
     </ComplexNode>
     
     <ComplexType type="NodeContainer">
         <NodeSet>
-            <Node minOcuur="0" maxOccur="unbounded" nodeName="ComplexNode" type="ComplexNode"/>
-            <Node minOcuur="0" maxOccur="unbounded" nodeName="SimpleNode" type="SimpleNode"/>
-            <SimpleNode minOcuur="0" maxOccur="unbounded" nodeName="Node"/>
+            <Node minOcuur="0" maxOccur="unbounded" name="ComplexNode" type="ComplexNode"/>
+            <Node minOcuur="0" maxOccur="unbounded" name="SimpleNode" type="SimpleNode"/>
+            <SimpleNode minOcuur="0" maxOccur="unbounded" name="Node"/>
         </NodeSet>
     </ComplexType>
     
     
     <ComplexType type="ComplexType">
         <NodeList>
-            <Node nodeName="NodeSet" type="NodeContainer" minOcuur=0/>
-            <Node nodeName="NodeList" type="NodeContainer" minOccur=0/>
+            <Node name="NodeSet" type="NodeContainer" minOcuur=0/>
+            <Node name="NodeList" type="NodeContainer" minOccur=0/>
             <AnyNode minOccur="0" maxOccur="unbounded"/>
         </NodeList>
     </ComplexType>
     
     <ComplexType type="ComplexNode">
         <NodeList>
-            <Node nodeName="NodeSet" type="NodeContainer" minOcuur=0/>
-            <Node nodeName="NodeList" type="NodeContainer" minOccur=0/>
+            <Node name="NodeSet" type="NodeContainer" minOcuur=0/>
+            <Node name="NodeList" type="NodeContainer" minOccur=0/>
             <AnyNode minOccur="0" maxOccur="unbounded"/>
         </NodeList>
     </ComplexType>