Hello,
I try to read through an XML document with the libxml-ruby SAX parser.
It is possible to execute the parser and I can see the output of the
element according to the “puts” in the Saxparser class.
However I do not know how to get the results after the
“on_start_element” and write them in to a hash. I’m browsing through
Google since 3 days without any luck to find an example or
understandable documentation how to get the data.
I need to get the data between and .
Is there anybody that can help me?
Thanks
I have done following:
Created a saxparser.rb model that looks like this:
require ‘rubygems’
require ‘xml/libxml’
class Saxparser
include XML::SaxParser::Callbacks
def on_start_element(element, attributes)
if element == ‘row’
puts element
end
end
end
Created method to execute the sax parser:
def self.vbdownload_td_xml
require ‘net/http’
# download the xml file
download_td_xml
parser = XML::SaxParser.file("#{RAILS_ROOT}/tmp/td.xml")
parser.callbacks = Saxparser.new
parser.parse
end
The XML itself looks like this:
Programm Name
…
Shop 1
45001
…