Namespace

Methods

Class/Module Index [+]

Quicksearch

Ruote::XmlParser

Turns an XML string into a process definition tree.

Public Class Methods

parse(s) click to toggle source

Parses the XML string into a process definition tree (array of arrays).

# File lib/ruote/parser/xml.rb, line 64
def self.parse (s)

  parser = REXML::Parsers::SAX2Parser.new(s)

  root = nil
  current = nil

  # u, l, q, a <=> url, local, qname, attributes

  parser.listen(:start_element) do |u, l, q, a|
    current = Node.new(current, l.gsub(/-/, '_'), a)
    root ||= current
  end
  parser.listen(:end_element) do |u, l, q, a|
    current = current.parent
  end

  parser.listen(:characters) do |text|
    t = text.strip
    current.attributes[t] = nil if t.size > 0
  end

  parser.parse

  root.to_a
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.