views:

35

answers:

1

Hi,

I want to parse a XML file, change some attributes and write the results in a new XML file. The given XML file is very huge (approx. 2 GB).

Does anyone have experiences handling such XML files using Ruby and can recommend me a library?

Best regards

+1  A: 

First, I am assuming that you are talking about changing some attributes on a bunch of elements. That being said, you do not want to read the whole document at once (DOM based parsing), you really want to deal with elements as you see them (SAX based parsing). I am not a ruby person, but a quick search turned up some good info on SAX parsing in Ruby, in particular this post http://lucaguidi.com/2008/01/30/ruby-xml-parsing-with-sax.

If you only have a few attributes on a small number of elements, then I would recommend a different approach. First, if you can specify the items you want to change as a regular expression it may be simpler to use a command-line tool like sed to edit the files.

Robert Diana
Jep, you're right. I want to remove some attributes in order to reduce the informations given in the xml file. Thanks for the link, it looks pretty interesting and I will have a look at it!
brainfck