| Module | REXML::Validation::Validator |
| In: |
lib/rexml/validation/validation.rb
|
| NILEVENT | = | [ nil ] |
# File lib/rexml/validation/validation.rb, line 7
7: def reset
8: @current = @root
9: @root.reset
10: @root.previous = true
11: @attr_stack = []
12: self
13: end
# File lib/rexml/validation/validation.rb, line 17
17: def validate( event )
18: #puts "Current: #@current"
19: #puts "Event: #{event.inspect}"
20: @attr_stack = [] unless defined? @attr_stack
21: match = @current.next(event)
22: raise ValidationException.new( "Validation error. Expected: "+
23: @current.expected.join( " or " )+" from #{@current.inspect} "+
24: " but got #{Event.new( event[0], event[1] ).inspect}" ) unless match
25: @current = match
26:
27: # Check for attributes
28: case event[0]
29: when :start_element
30: #puts "Checking attributes"
31: @attr_stack << event[2]
32: begin
33: sattr = [:start_attribute, nil]
34: eattr = [:end_attribute]
35: text = [:text, nil]
36: k,v = event[2].find { |k,v|
37: sattr[1] = k
38: #puts "Looking for #{sattr.inspect}"
39: m = @current.next( sattr )
40: #puts "Got #{m.inspect}"
41: if m
42: # If the state has text children...
43: #puts "Looking for #{eattr.inspect}"
44: #puts "Expect #{m.expected}"
45: if m.matches?( eattr )
46: #puts "Got end"
47: @current = m
48: else
49: #puts "Didn't get end"
50: text[1] = v
51: #puts "Looking for #{text.inspect}"
52: m = m.next( text )
53: #puts "Got #{m.inspect}"
54: text[1] = nil
55: return false unless m
56: @current = m if m
57: end
58: m = @current.next( eattr )
59: if m
60: @current = m
61: true
62: else
63: false
64: end
65: else
66: false
67: end
68: }
69: event[2].delete(k) if k
70: end while k
71: when :end_element
72: attrs = @attr_stack.pop
73: raise ValidationException.new( "Validation error. Illegal "+
74: " attributes: #{attrs.inspect}") if attrs.length > 0
75: end
76: end