Class: REXML::Validation::RelaxNG

Inherits:
Object
  • Object
show all
Includes:
Validator
Defined in:
lib/rexml/validation/relaxng.rb

Overview

Implemented:

  • empty

  • element

  • attribute

  • text

  • optional

  • choice

  • oneOrMore

  • zeroOrMore

  • group

  • value

  • interleave

  • mixed

  • ref

  • grammar

  • start

  • define

Not implemented:

  • data

  • param

  • include

  • externalRef

  • notAllowed

  • anyName

  • nsName

  • except

  • name

Constant Summary collapse

INFINITY =
1.0 / 0.0
EMPTY =
Event.new( nil )
TEXT =
[:start_element, "text"]

Constants included from Validator

Validator::NILEVENT

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Validator

#dump, #reset, #validate

Constructor Details

#initialize(source) ⇒ RelaxNG

FIXME: Namespaces



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/rexml/validation/relaxng.rb', line 46

def initialize source
  parser = REXML::Parsers::BaseParser.new( source )

  @count = 0
  @references = {}
  @root = @current = Sequence.new(self)
  @root.previous = true
  states = [ @current ]
  begin
    event = parser.pull
    case event[0]
    when :start_element
      case event[1]
      when "empty"
      when "element", "attribute", "text", "value"
        states[-1] << event
      when "optional"
        states << Optional.new( self )
        states[-2] << states[-1]
      when "choice"
        states << Choice.new( self )
        states[-2] << states[-1]
      when "oneOrMore"
        states << OneOrMore.new( self )
        states[-2] << states[-1]
      when "zeroOrMore"
        states << ZeroOrMore.new( self )
        states[-2] << states[-1]
      when "group"
        states << Sequence.new( self )
        states[-2] << states[-1]
      when "interleave"
        states << Interleave.new( self )
        states[-2] << states[-1]
      when "mixed"
        states << Interleave.new( self )
        states[-2] << states[-1]
        states[-1] << TEXT
      when "define"
        states << [ event[2]["name"] ]
      when "ref"
        states[-1] << Ref.new( event[2]["name"] )
      when "anyName"
        states << AnyName.new( self )
        states[-2] << states[-1]
      when "nsName"
      when "except"
      when "name"
      when "data"
      when "param"
      when "include"
      when "grammar"
      when "start"
      when "externalRef"
      when "notAllowed"
      end
    when :end_element
      case event[1]
      when "element", "attribute"
        states[-1] << event
      when "zeroOrMore", "oneOrMore", "choice", "optional",
        "interleave", "group", "mixed"
        states.pop
      when "define"
        ref = states.pop
        @references[ ref.shift ] = ref
      #when "empty"
      end
    when :end_document
      states[-1] << event
    when :text
      states[-1] << event
    end
  end while event[0] != :end_document
end

Instance Attribute Details

#countObject

Returns the value of attribute count.



42
43
44
# File 'lib/rexml/validation/relaxng.rb', line 42

def count
  @count
end

#currentObject

Returns the value of attribute current.



41
42
43
# File 'lib/rexml/validation/relaxng.rb', line 41

def current
  @current
end

#referencesObject (readonly)

Returns the value of attribute references.



43
44
45
# File 'lib/rexml/validation/relaxng.rb', line 43

def references
  @references
end

Instance Method Details

#receive(event) ⇒ Object



122
123
124
# File 'lib/rexml/validation/relaxng.rb', line 122

def receive event
  validate( event )
end