#!/usr/bin/env ruby

require "xmlparser"

def getExamples(filename)
  examples = {}
  parser = XMLParser.new
  parser.parse(File.open(filename)) { | type, name, data |
    current = nil 
    case type
      when XMLParser::START_ELEM
        if name == "example"
          current = data["name"]
          puts current
        end
      when XMLParser::END_ELEM
        if name == "example"
          current = nil
        end
      when XMLParser::CDATA
        if current
          examples[current] += data
        end
    end
  }
  parser.done
  examples
end

examples = getExamples("examples.xml")
