class Arboretum::XML::IO::ArboretumSax

Attributes

tree[RW]

Public Class Methods

new(style) click to toggle source
# File lib/arboretum/xml.rb, line 49
def initialize(style)
  # Must initalize line to have access
  @line = nil # Integer

  # Root document element
  root = DocRootElement.new # DocRootElement

  # Intialize a tree for the parser to build on
  @tree = Tree.new(root)    # Tree

  # Contextual information for parsing process
  @open_elements = [root]    # Array of Elements

  # Read style
  @style = style
end

Public Instance Methods

abort(name) click to toggle source
# File lib/arboretum/xml.rb, line 161
def abort(name)
  args = method(__method__).parameters.map {|_,arg_name| binding.local_variable_get(arg_name)}
  reason = "Unimplemented method"
  self.print_read_failure(__method__, args, reason)
end
attr(name, str) click to toggle source
# File lib/arboretum/xml.rb, line 94
def attr(name, str)
  # Get the most recently opened element
  most_recent_open = @open_elements.last
  # Append found values to attribute
  most_recent_open.add_attr_value(name, str)
end
cdata(str) click to toggle source
# File lib/arboretum/xml.rb, line 151
def cdata(str)
  args = method(__method__).parameters.map {|_,arg_name| binding.local_variable_get(arg_name)}
  reason = "Unimplemented method"
  self.print_read_failure(__method__, args, reason)
end
comment(str) click to toggle source
# File lib/arboretum/xml.rb, line 100
def comment(str)
  # Add CommentElement to tree
  comment_element = CommentElement.new(str)
  comment_element.graft_last_onto(@open_elements.last)
  # Do not open the element (no children)
end
doctype(str) click to toggle source
# File lib/arboretum/xml.rb, line 146
def doctype(str)
  args = method(__method__).parameters.map {|_,arg_name| binding.local_variable_get(arg_name)}
  reason = "Unimplemented method"
  self.print_read_failure(__method__, args, reason)
end
end_element(name) click to toggle source
# File lib/arboretum/xml.rb, line 123
def end_element(name)
  # Close the most recent element/Get the closed element
  closed_element = @open_elements.pop

  # Partially ensure the correct element has been closed
  if not "#{closed_element.namespaced_tag}".eql?(name.to_s)
    args = method(__method__).parameters.map {|_,arg_name| binding.local_variable_get(arg_name)}
    reason = "Non-matching element open/close tags: #{closed_element.tag} and #{name}"
    self.print_read_failure(__method__, args, reason)
  end
end
end_instruct(target) click to toggle source
# File lib/arboretum/xml.rb, line 141
def end_instruct(target)
  args = method(__method__).parameters.map {|_,arg_name| binding.local_variable_get(arg_name)}
  reason = "Unimplemented method"
  self.print_read_failure(__method__, args, reason)
end
error(msg, line, column) click to toggle source
# File lib/arboretum/xml.rb, line 156
def error(msg, line, column)
  args = method(__method__).parameters.map {|_,arg_name| binding.local_variable_get(arg_name)}
  reason = "A read error occured"
  self.print_read_failure(__method__, args, reason)
end
instruct(target) click to toggle source

Unimplemented calls w/debug output

# File lib/arboretum/xml.rb, line 136
def instruct(target)
  args = method(__method__).parameters.map {|_,arg_name| binding.local_variable_get(arg_name)}
  reason = "Unimplemented method"
  self.print_read_failure(__method__, args, reason)
end
print_read_failure(method_name, args, reason="None given...") click to toggle source
start_element(name) click to toggle source
# File lib/arboretum/xml.rb, line 74
def start_element(name)
  # Extract namespace if one exists
  element_ns = nil
  element_tag = name
  tag_str = name.to_s
  if tag_str.include?(':')
    tag_split = tag_str.split(':')
    raise XMLParseException if tag_split.length != 2
    # Final information
    element_ns = tag_split[0].to_sym
    element_tag = tag_split[1].to_sym
  end

  # Add TaggedElement to tree
  opened_element = TaggedElement.new(element_ns, element_tag)
  opened_element.graft_last_onto(@open_elements.last)

  # Open the element if paired
  @open_elements.push(opened_element)
end
text(str) click to toggle source
# File lib/arboretum/xml.rb, line 106
def text(str)
  if @style == :clean
    # Compress, but preserve, whitespace
    str.gsub!(/\s+/, ' ')

    # Add TextElement to tree
    text_element = TextElement.new(str)
    text_element.graft_last_onto(@open_elements.last)
    # Do not open the element (no children)

  elsif @style == :preserve
    # Add TextElement to tree
    text_element = TextElement.new(str)
    text_element.graft_last_onto(@open_elements.last)
    # Do not open the element (no children)
  end
end