SAX2Parser, anyone?

  • Thread starter Krister Johnson
  • Start date
K

Krister Johnson

Hi guys.

I'm trying to mine some info from wikipedia's xml dump. The code im
using is as follows:

require 'rexml/parsers/sax2parser'
xml = REXML::parsers:SAX2Parser.new(File.new('enwiki-20070402-pages-articles-1.xml')
)

i = 0
parser.listen:)characters, %w{title text}){|text| puts text}
parser.parse

Which is generating the error:
xmlreap.rb:2: undefined method `new' for :SAX2Parser:Symbol (NoMethodError)

Anyone have any experience with SAX2? Or ruby stream parsing in
general? What I'm trying to do is pretty simple: grab the title and
text tag element contents and do something with them.

Thanks,
Krister Johnson
 
J

James Britt

Krister said:
Hi guys.

I'm trying to mine some info from wikipedia's xml dump. The code im
using is as follows:

require 'rexml/parsers/sax2parser'
xml =
REXML::parsers:SAX2Parser.new(File.new('enwiki-20070402-pages-articles-1.xml')

)

i = 0
parser.listen:)characters, %w{title text}){|text| puts text}
parser.parse

Which is generating the error:
xmlreap.rb:2: undefined method `new' for :SAX2Parser:Symbol (NoMethodError)

Anyone have any experience with SAX2? Or ruby stream parsing in
general? What I'm trying to do is pretty simple: grab the title and
text tag element contents and do something with them.

I may have something useful here:

http://www.jamesbritt.com/content
 
S

Sylvain Joyeux

Hi guys.

I'm trying to mine some info from wikipedia's xml dump. The code im
using is as follows:

require 'rexml/parsers/sax2parser'
xml =
REXML::parsers:SAX2Parser.new(File.new('enwiki-20070402-pages-articles-1
.xml') )

i = 0
parser.listen:)characters, %w{title text}){|text| puts text}
parser.parse

Which is generating the error:
xmlreap.rb:2: undefined method `new' for :SAX2Parser:Symbol
(NoMethodError)

This is a syntax error. You have written
REXML::parsers:SAX2Parser.new()
which, I guess, is interpreted as
REXML::parsers:)SAX2Parser.new())

but :SAX2Parser is a symbol, and there is no new method on it ...
You wanted (two ':')
REXML::parsers::SAX2Parser.new()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,252
Latest member
MeredithPl

Latest Threads

Top