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 <row> and </row>.
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:
-----------------------------------------------------------------
<report title="Event breakdown report"
name="aAffiliateEventBreakdownReport" time="2011-01-25
22:14">
<matrix rowcount="310">
<columns>
<programName type="string">Programm
Name</programName>
...
</columns>
<rows>
<row>
<programName>Shop 1</programName>
<programId>45001</programId>
...
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Chris, the SAX Parser has an "on_characters" callback. You need to note when you see an on_start_tag for the tag "row". Then, in your on_characters callback, you use the characters it presents you. When you see an end tag for "row", you need to turn off your note. Get it? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.