[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

SAX2Parser, anyone?

Krister Johnson

5/6/2007 5:48:00 AM

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

3 Answers

James Britt

5/6/2007 7:11:00 AM

0

Krister Johnson wrote:
> 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.c...


--
James Britt



Sylvain Joyeux

5/6/2007 7:59:00 AM

0

On Sunday 06 May 2007, Krister Johnson wrote:
> 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()

--
Sylvain Joyeux

Krister Johnson

5/6/2007 8:41:00 AM

0

oh no. that really was it. (slaps forehead)

thanks.

krister

On 5/6/07, Sylvain Joyeux <sylvain.joyeux@polytechnique.org> wrote:
> On Sunday 06 May 2007, Krister Johnson wrote:
> > 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()
>
> --
> Sylvain Joyeux
>
>