[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

memory considerations when parsing XML file

Mr_Tibs

1/31/2008 7:36:00 PM

Hi,

I need to quickly parse a large XML file. I didn't want to use DOM
parsing since this way you end up with the whole file in the memory. I
looked at writing my own SAX-style parser and came across this post:
http://www.janvereecken.com/2007/4/11/event-driven-xml-pars....

My question is about reading the file from the hard drive into the
parse_stream method:
REXML::Document.parse_stream(File.open(filename).read, MyListener.new)
Won't File.open...read read the whole file in the memory? If yes, then
nothing was gained. I might just as well read and parse the document
using DOM since it is easier.

Thanks,
Tiberiu
2 Answers

Mr_Tibs

1/31/2008 7:56:00 PM

0

I'm sorry for rushing with the post. I just read that parse_stream
also takes an IO object, so I don't have to do read on the filename.

Tiberiu

Robert Klemme

1/31/2008 10:22:00 PM

0

On 31.01.2008 20:56, Mr_Tibs wrote:
> I'm sorry for rushing with the post. I just read that parse_stream
> also takes an IO object, so I don't have to do read on the filename.

:-)

And the idiom should rather read

File.open(filename, 'rb') do |io|
REXML::Document.parse_stream(io, MyListener.new)
end

i.e. use the block form of File.open.

robert