J
JP
Hi, i just started to learn ruby today and run into annoying problem, i
don't quite get what's
wrong in the code snippet below, what i try to do is simple count all
"document" elements from xml file
why it complains this:
xmlreader.rb:33:in `tag_start': undefined method `+' for nil:NilClass
(NoMethodError)
from f:/ruby/lib/ruby/1.8/rexml/parsers/streamparser.rb:24:in `parse'
sum is undefined? but why? here's the code:
require "rexml/document"
include REXML
class Listener
sum=0
def text(text)
puts text
end
def xmldecl(version,encoding,standalone)
puts version
puts encoding
end
def tag_start(name,attrs)
if name == "document"
sum += 1
end
end
def tag_end(name)
end
end
list = Listener.new
xmlfile = File.new( "f:\\data2\\mloy\\out\\mtl009index.3.xml")
sparser = Parsers::StreamParser.new(xmlfile,list)
sparser.parse()
puts sum
don't quite get what's
wrong in the code snippet below, what i try to do is simple count all
"document" elements from xml file
why it complains this:
xmlreader.rb:33:in `tag_start': undefined method `+' for nil:NilClass
(NoMethodError)
from f:/ruby/lib/ruby/1.8/rexml/parsers/streamparser.rb:24:in `parse'
sum is undefined? but why? here's the code:
require "rexml/document"
include REXML
class Listener
sum=0
def text(text)
puts text
end
def xmldecl(version,encoding,standalone)
puts version
puts encoding
end
def tag_start(name,attrs)
if name == "document"
sum += 1
end
end
def tag_end(name)
end
end
list = Listener.new
xmlfile = File.new( "f:\\data2\\mloy\\out\\mtl009index.3.xml")
sparser = Parsers::StreamParser.new(xmlfile,list)
sparser.parse()
puts sum