class Ox::Sax

A SAX style parse handler. The Ox::Sax handler class should be subclasses and then used with the Ox.sax_parse method. The Sax methods will then be called as the file is parsed. This is best suited for very large files or IO streams.<p/>

Example

require 'ox'

class MySax < ::Ox::Sax
  def initialize()
    @element_name = []
  end

  def start_element(name)
    @element_names << name
  end
end

any = MySax.new()
File.open('any.xml', 'r') do |f|
  Ox.sax_parse(any, f)
end

To make the desired methods active while parsing the desired method should be made public in the subclasses. If the methods remain private they will not be called during parsing. The 'name' argument in the callback methods will be a Symbol. The 'str' arguments will be a String. The 'value' arguments will be Ox::Sax::Value objects. Since both the text() and the value() methods are called for the same element in the XML document the the text() method is ignored if the value() method is defined or public. The same is true for attr() and #attr_value(). When all attribtues have been read the attr_done() callback will be invoked.

def instruct(target); end
def end_instruct(target); end
def attr(name, str); end
def attr_value(name, value); end
def attrs_done(); end
def doctype(str); end
def comment(str); end
def cdata(str); end
def text(str); end
def value(value); end
def start_element(name); end
def end_element(name); end
def error(message, line, column); end
def abort(name); end

Initializing line attribute in the initializer will cause that variable to be updated before each callback with the XML line number. The same is true for the column attribute but it will be updated with the column in the XML file that is the start of the element or node just read. @pos if defined will hold the number of bytes from the start of the document.

Public Class Methods

new() click to toggle source

Create a new instance of the Sax handler class.

# File lib/ox/sax.rb, line 59
def initialize()
  #@pos = nil
  #@line = nil
  #@column = nil
end

Private Instance Methods

abort(name) click to toggle source
# File lib/ox/sax.rb, line 109
def abort(name)
end
attr(name, str) click to toggle source
# File lib/ox/sax.rb, line 76
def attr(name, str)
end
attr_value(name, value) click to toggle source
# File lib/ox/sax.rb, line 79
def attr_value(name, value)
end
attrs_done() click to toggle source
# File lib/ox/sax.rb, line 82
def attrs_done()
end
cdata(str) click to toggle source
# File lib/ox/sax.rb, line 91
def cdata(str)
end
comment(str) click to toggle source
# File lib/ox/sax.rb, line 88
def comment(str)
end
doctype(str) click to toggle source
# File lib/ox/sax.rb, line 85
def doctype(str)
end
end_element(name) click to toggle source
# File lib/ox/sax.rb, line 103
def end_element(name)
end
end_instruct(target) click to toggle source
# File lib/ox/sax.rb, line 73
def end_instruct(target)
end
error(message, line, column) click to toggle source
# File lib/ox/sax.rb, line 106
def error(message, line, column)
end
instruct(target) click to toggle source

To make the desired methods active while parsing the desired method should be made public in the subclasses. If the methods remain private they will not be called during parsing.

# File lib/ox/sax.rb, line 70
def instruct(target)
end
start_element(name) click to toggle source
# File lib/ox/sax.rb, line 100
def start_element(name)
end
text(str) click to toggle source
# File lib/ox/sax.rb, line 94
def text(str)
end
value(value) click to toggle source
# File lib/ox/sax.rb, line 97
def value(value)
end