Hi,
i've installed libxml-ruby (0.5.2.0) and want to test the SaxParser.
So I found following example:
#!/usr/bin/env ruby
require 'rubygems'
require 'xml/libxml'
start = Time.now
ARGV.each {|filename|
counts = Hash.new
parser = XML::SaxParser.new
parser.filename = filename
parser.on_start_element {|element_name, _|
if counts[element_name]
counts[element_name] += 1
else
counts[element_name] = 1
end
}
parser.parse
File.open(filename + ".count.csv", "w") {|f|
counts.each {|element_name, count|
f.puts "\"#{element_name}\",#{count}"
}
}
}
but if I start this script, I got following error:
undefined method `on_start_element' for #<XML::SaxParser:0xb7a88858>
(NoMethodError)
but why? a saw a few examples with "on_start_element".
thanks!
You might have the wrong lib in your mind: http://p.ramaze.net/9 would work
···
On Dec 19, 2007 9:35 PM, funkdoobiest <jan.thoelken@gmail.com> wrote:
Hi,
i've installed libxml-ruby (0.5.2.0) and want to test the SaxParser.
So I found following example:
#!/usr/bin/env ruby
require 'rubygems'
require 'xml/libxml'
start = Time.now
ARGV.each {|filename|
counts = Hash.new
parser = XML::SaxParser.new
parser.filename = filename
parser.on_start_element {|element_name, _|
if counts[element_name]
counts[element_name] += 1
else
counts[element_name] = 1
end
}
parser.parse
File.open(filename + ".count.csv", "w") {|f|
counts.each {|element_name, count|
f.puts "\"#{element_name}\",#{count}"
}
}
}
but if I start this script, I got following error:
undefined method `on_start_element' for #<XML::SaxParser:0xb7a88858>
(NoMethodError)
but why? a saw a few examples with "on_start_element".
thank you! that works. you saved my day 
···
On 19 Dez., 14:27, Michael Fellinger <m.fellin...@gmail.com> wrote:
On Dec 19, 2007 9:35 PM, funkdoobiest <jan.thoel...@gmail.com> wrote:
> Hi,
> i've installed libxml-ruby (0.5.2.0) and want to test the SaxParser.
> So I found following example:
> #!/usr/bin/env ruby
> require 'rubygems'
> require 'xml/libxml'
> start = Time.now
> ARGV.each {|filename|
> counts = Hash.new
> parser = XML::SaxParser.new
> parser.filename = filename
> parser.on_start_element {|element_name, _|
> if counts[element_name]
> counts[element_name] += 1
> else
> counts[element_name] = 1
> end
> }
> parser.parse
> File.open(filename + ".count.csv", "w") {|f|
> counts.each {|element_name, count|
> f.puts "\"#{element_name}\",#{count}"
> }
> }
> }
> but if I start this script, I got following error:
> undefined method `on_start_element' for #<XML::SaxParser:0xb7a88858>
> (NoMethodError)
> but why? a saw a few examples with "on_start_element".
You might have the wrong lib in your mind:http://p.ramaze.net/9would work