1 require 'rexml/validation/validationexception'
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
27 # Check for attributes
30 #puts "Checking attributes"
31 @attr_stack << event[2]
33 sattr = [:start_attribute, nil]
34 eattr = [:end_attribute]
36 k,v = event[2].find { |k,v|
38 #puts "Looking for #{sattr.inspect}"
39 m = @current.next( sattr )
40 #puts "Got #{m.inspect}"
42 # If the state has text children...
43 #puts "Looking for #{eattr.inspect}"
44 #puts "Expect #{m.expected}"
45 if m.matches?( eattr )
49 #puts "Didn't get end"
51 #puts "Looking for #{text.inspect}"
53 #puts "Got #{m.inspect}"
58 m = @current.next( eattr )
69 event[2].delete(k) if k
72 attrs = @attr_stack.pop
73 raise ValidationException.new( "Validation error. Illegal "+
74 " attributes: #{attrs.inspect}") if attrs.length > 0
80 def initialize(event_type, event_arg=nil )
81 @event_type = event_type
82 @event_arg = event_arg
85 attr_reader :event_type
86 attr_accessor :event_arg
93 return (@event_type != :start_element and @event_type != :start_attribute)
97 #puts "#@event_type =? #{event[0]} && #@event_arg =? #{event[1]} "
98 return false unless event[0] == @event_type
103 return true if event[1] == @event_arg
106 when :start_attribute
107 return true if event[1] == @event_arg
113 return (@event_arg.nil? or @event_arg == event[1])
115 when :processing_instruction
142 return false unless other.kind_of? Event
143 @event_type == other.event_type and @event_arg == other.event_arg
151 "#{@event_type.inspect}( #@event_arg )"