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

DOM Schema
author Sergey
date Tue, 22 Sep 2009 17:17:38 +0400
parents 1ca530e5c9c5
children fafe56cfcd69
comparison
equal deleted inserted replaced
19:1ca530e5c9c5 20:267460284fb3
32 } 32 }
33 33
34 sub Validate { 34 sub Validate {
35 my ($this,$node) = @_; 35 my ($this,$node) = @_;
36 36
37 #return IMPL::DOM::Schema::NodeSet->new()->appendRange(@{$this->childNodes})->Validate($node); 37 if ( my ($schemaNode) = $this->selectNodes(sub { $_[0]->name eq $node->nodeName })) {
38 $schemaNode->Validate($node);
39 } else {
40 return IMPL::DOM::Schema::VaidationError(Message=> "A specified document doesn't match the schema");
41 }
38 } 42 }
39 43
40 my $schema; 44 my $schema;
41 45
42 sub MetaSchema { 46 sub MetaSchema {
44 return $schema if $schema; 48 return $schema if $schema;
45 49
46 $schema = new IMPL::DOM::Schema(nodeName => 'schema'); 50 $schema = new IMPL::DOM::Schema(nodeName => 'schema');
47 51
48 $schema->appendRange( 52 $schema->appendRange(
49 IMPL::DOM::Schema::ComplexNode->new(nodeName => 'schema')->appendRange( 53 IMPL::DOM::Schema::ComplexNode->new(name => 'schema')->appendRange(
50 IMPL::DOM::Schema::NodeSet->new()->appendRange( 54 IMPL::DOM::Schema::NodeSet->new()->appendRange(
51 IMPL::DOM::Schema::Node->new(nodeName => 'ComplexNode', type => 'ComplexNode', minOccur => 0, maxOccur=>'unbounded'), 55 IMPL::DOM::Schema::Node->new(name => 'ComplexNode', type => 'ComplexNode', minOccur => 0, maxOccur=>'unbounded'),
52 IMPL::DOM::Schema::Node->new(nodeName => 'ComplexType', type => 'ComplexType', minOccur => 0, maxOccur=>'unbounded'), 56 IMPL::DOM::Schema::Node->new(name => 'ComplexType', type => 'ComplexType', minOccur => 0, maxOccur=>'unbounded'),
53 IMPL::DOM::Schema::Node->new(nodeName => 'SimpleNode', type => 'SimpleNode', minOccur => 0, maxOccur=>'unbounded'), 57 IMPL::DOM::Schema::Node->new(name => 'SimpleNode', type => 'SimpleNode', minOccur => 0, maxOccur=>'unbounded'),
54 IMPL::DOM::Schema::Node->new(nodeName => 'SimpleType', type => 'SimpleType', minOccur => 0, maxOccur=>'unbounded'), 58 IMPL::DOM::Schema::Node->new(name => 'SimpleType', type => 'SimpleType', minOccur => 0, maxOccur=>'unbounded'),
55 IMPL::DOM::Schema::SimpleNode->new(nodeName => 'Node', minOccur => 0, maxOccur=>'unbounded'), 59 IMPL::DOM::Schema::SimpleNode->new(name => 'Node', minOccur => 0, maxOccur=>'unbounded'),
56 IMPL::DOM::Schema::SimpleNode->new(nodeName => 'Include', minOccur => 0, maxOccur=>'unbounded') 60 IMPL::DOM::Schema::SimpleNode->new(name => 'Include', minOccur => 0, maxOccur=>'unbounded')
57 ), 61 ),
58 ), 62 ),
59 IMPL::DOM::Schema::ComplexType->new(type => 'NodeSet', nativeType => 'IMPL::DOM::Schema::NodeSet')->appendRange( 63 IMPL::DOM::Schema::ComplexType->new(type => 'NodeSet', nativeType => 'IMPL::DOM::Schema::NodeSet')->appendRange(
60 IMPL::DOM::Schema::NodeSet->new()->appendRange( 64 IMPL::DOM::Schema::NodeSet->new()->appendRange(
61 IMPL::DOM::Schema::Node->new(nodeName => 'ComplexNode', type => 'ComplexNode', minOccur => 0, maxOccur=>'unbounded'), 65 IMPL::DOM::Schema::Node->new(name => 'ComplexNode', type => 'ComplexNode', minOccur => 0, maxOccur=>'unbounded'),
62 IMPL::DOM::Schema::Node->new(nodeName => 'SimpleNode', type => 'SimpleNode', minOccur => 0, maxOccur=>'unbounded'), 66 IMPL::DOM::Schema::Node->new(name => 'SimpleNode', type => 'SimpleNode', minOccur => 0, maxOccur=>'unbounded'),
63 IMPL::DOM::Schema::SimpleNode->new(nodeName => 'Node', minOccur => 0, maxOccur=>'unbounded'), 67 IMPL::DOM::Schema::SimpleNode->new(name => 'Node', minOccur => 0, maxOccur=>'unbounded'),
64 ) 68 )
65 ), 69 ),
66 IMPL::DOM::Schema::ComplexType->new(type => 'NodeList', nativeType => 'IMPL::DOM::Schema::NodeList')->appendRange( 70 IMPL::DOM::Schema::ComplexType->new(type => 'NodeList', nativeType => 'IMPL::DOM::Schema::NodeList')->appendRange(
67 IMPL::DOM::Schema::NodeSet->new()->appendRange( 71 IMPL::DOM::Schema::NodeSet->new()->appendRange(
68 IMPL::DOM::Schema::Node->new(nodeName => 'ComplexNode', type => 'ComplexNode', minOccur => 0, maxOccur=>'unbounded'), 72 IMPL::DOM::Schema::Node->new(name => 'ComplexNode', type => 'ComplexNode', minOccur => 0, maxOccur=>'unbounded'),
69 IMPL::DOM::Schema::Node->new(nodeName => 'SimpleNode', type => 'SimpleNode', minOccur => 0, maxOccur=>'unbounded'), 73 IMPL::DOM::Schema::Node->new(name => 'SimpleNode', type => 'SimpleNode', minOccur => 0, maxOccur=>'unbounded'),
70 IMPL::DOM::Schema::SimpleNode->new(nodeName => 'Node', minOccur => 0, maxOccur=>'unbounded'), 74 IMPL::DOM::Schema::SimpleNode->new(name => 'Node', minOccur => 0, maxOccur=>'unbounded'),
71 ) 75 )
72 ), 76 ),
73 IMPL::DOM::Schema::ComplexType->new(type => 'ComplexType', nativeType => 'IMPL::DOM::Schema::ComplexType')->appendRange( 77 IMPL::DOM::Schema::ComplexType->new(type => 'ComplexType', nativeType => 'IMPL::DOM::Schema::ComplexType')->appendRange(
74 IMPL::DOM::Schema::NodeList->new()->appendRange( 78 IMPL::DOM::Schema::NodeList->new()->appendRange(
75 IMPL::DOM::Schema::Node->new(nodeName => 'NodeSet', minOccur => 0, type => 'NodeSet'), 79 IMPL::DOM::Schema::Node->new(name => 'NodeSet', minOccur => 0, type => 'NodeSet'),
76 IMPL::DOM::Schema::Node->new(nodeName => 'NodeList', minOccur => 0, type => 'NodeSet'), 80 IMPL::DOM::Schema::Node->new(name => 'NodeList', minOccur => 0, type => 'NodeSet'),
77 IMPL::DOM::Schema::SimpleNode->new(nodeName => 'Node', minOccur => 0, maxOccur => 'unbounded') 81 IMPL::DOM::Schema::SimpleNode->new(name => 'Node', minOccur => 0, maxOccur => 'unbounded')
78 ) 82 )
79 ), 83 ),
80 IMPL::DOM::Schema::ComplexType->new(type => 'ComplexNode', nativeType => 'IMPL::DOM::Schema::ComplexNode')->appendRange( 84 IMPL::DOM::Schema::ComplexType->new(type => 'ComplexNode', nativeType => 'IMPL::DOM::Schema::ComplexNode')->appendRange(
81 IMPL::DOM::Schema::NodeList->new()->appendRange( 85 IMPL::DOM::Schema::NodeList->new()->appendRange(
82 IMPL::DOM::Schema::Node->new(nodeName => 'NodeSet', minOccur => 0, type => 'NodeSet'), 86 IMPL::DOM::Schema::Node->new(name => 'NodeSet', minOccur => 0, type => 'NodeSet'),
83 IMPL::DOM::Schema::Node->new(nodeName => 'NodeList', minOccur => 0, type => 'NodeSet'), 87 IMPL::DOM::Schema::Node->new(name => 'NodeList', minOccur => 0, type => 'NodeSet'),
84 IMPL::DOM::Schema::SimpleNode->new(nodeName => 'Node', minOccur => 0, maxOccur => 'unbounded') 88 IMPL::DOM::Schema::SimpleNode->new(name => 'Node', minOccur => 0, maxOccur => 'unbounded')
85 ) 89 )
86 ), 90 ),
87 IMPL::DOM::Schema::ComplexType->new(type => 'SimpleType', nativeType => 'IMPL::DOM::Schema::SimpleType')->appendRange( 91 IMPL::DOM::Schema::ComplexType->new(type => 'SimpleType', nativeType => 'IMPL::DOM::Schema::SimpleType')->appendRange(
88 IMPL::DOM::Schema::NodeSet->new()->appendRange( 92 IMPL::DOM::Schema::NodeSet->new()->appendRange(
89 IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0) 93 IMPL::DOM::Schema::AnyNode->new(maxOccur => 'unbounded', minOccur => 0)
123 127
124 Возвращает схему типа c именем C<$typeName>. 128 Возвращает схему типа c именем C<$typeName>.
125 129
126 =back 130 =back
127 131
132 =head1 DESCRIPTION
133
134 DOM схема - это документ, состоящий из определенных узлов, описывающая структуру
135 других документов.
136
128 =head1 META SCHEMA 137 =head1 META SCHEMA
129 138
130 Схема для описания схемы, эта схема используется для постороения других схем 139 Схема для описания схемы, эта схема используется для постороения других схем
131 140
132 <schema> 141 <schema>
133 <ComplexNode nodeName="schema"> 142 <ComplexNode name="schema">
134 <NodeSet> 143 <NodeSet>
135 <Node minOcuur="0" maxOccur="unbounded" nodeName="ComplexNode" type="ComplexNode"/> 144 <Node minOcuur="0" maxOccur="unbounded" name="ComplexNode" type="ComplexNode"/>
136 <Node minOcuur="0" maxOccur="unbounded" nodeName="SimpleNode" type="SimpleNode"/> 145 <Node minOcuur="0" maxOccur="unbounded" name="SimpleNode" type="SimpleNode"/>
137 <Node minOcuur="0" maxOccur="unbounded" nodeName="ComplexType" type="ComplexType"/> 146 <Node minOcuur="0" maxOccur="unbounded" name="ComplexType" type="ComplexType"/>
138 <Node minOcuur="0" maxOccur="unbounded" nodeName="SimpleType" type="SimpleType"/> 147 <Node minOcuur="0" maxOccur="unbounded" name="SimpleType" type="SimpleType"/>
139 <SimpleNode minOcuur="0" maxOccur="unbounded" nodeName="Node"/> 148 <SimpleNode minOcuur="0" maxOccur="unbounded" name="Node"/>
140 <SimpleNode minOcuur="0" maxOccur="unbounded" nodeName="Include"/> 149 <SimpleNode minOcuur="0" maxOccur="unbounded" name="Include"/>
141 </NodeSet> 150 </NodeSet>
142 </ComplexNode> 151 </ComplexNode>
143 152
144 <ComplexType type="NodeContainer"> 153 <ComplexType type="NodeContainer">
145 <NodeSet> 154 <NodeSet>
146 <Node minOcuur="0" maxOccur="unbounded" nodeName="ComplexNode" type="ComplexNode"/> 155 <Node minOcuur="0" maxOccur="unbounded" name="ComplexNode" type="ComplexNode"/>
147 <Node minOcuur="0" maxOccur="unbounded" nodeName="SimpleNode" type="SimpleNode"/> 156 <Node minOcuur="0" maxOccur="unbounded" name="SimpleNode" type="SimpleNode"/>
148 <SimpleNode minOcuur="0" maxOccur="unbounded" nodeName="Node"/> 157 <SimpleNode minOcuur="0" maxOccur="unbounded" name="Node"/>
149 </NodeSet> 158 </NodeSet>
150 </ComplexType> 159 </ComplexType>
151 160
152 161
153 <ComplexType type="ComplexType"> 162 <ComplexType type="ComplexType">
154 <NodeList> 163 <NodeList>
155 <Node nodeName="NodeSet" type="NodeContainer" minOcuur=0/> 164 <Node name="NodeSet" type="NodeContainer" minOcuur=0/>
156 <Node nodeName="NodeList" type="NodeContainer" minOccur=0/> 165 <Node name="NodeList" type="NodeContainer" minOccur=0/>
157 <AnyNode minOccur="0" maxOccur="unbounded"/> 166 <AnyNode minOccur="0" maxOccur="unbounded"/>
158 </NodeList> 167 </NodeList>
159 </ComplexType> 168 </ComplexType>
160 169
161 <ComplexType type="ComplexNode"> 170 <ComplexType type="ComplexNode">
162 <NodeList> 171 <NodeList>
163 <Node nodeName="NodeSet" type="NodeContainer" minOcuur=0/> 172 <Node name="NodeSet" type="NodeContainer" minOcuur=0/>
164 <Node nodeName="NodeList" type="NodeContainer" minOccur=0/> 173 <Node name="NodeList" type="NodeContainer" minOccur=0/>
165 <AnyNode minOccur="0" maxOccur="unbounded"/> 174 <AnyNode minOccur="0" maxOccur="unbounded"/>
166 </NodeList> 175 </NodeList>
167 </ComplexType> 176 </ComplexType>
168 177
169 <ComplexType type="SimpleNode"> 178 <ComplexType type="SimpleNode">