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
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.