I would like to build a Rails application to import the data from a XML file into a MySQL database. Any help?
Asked
Active
Viewed 2,081 times
1
-
Import it into an ORM that accepts XML, and save. – Denis de Bernardy Jun 02 '11 at 10:03
-
A noob here. Any code that you can point me to? – Aditya Vikram Thoomati Jun 02 '11 at 10:05
-
Did you try http://www.google.com/search?q=ORM+import+XML+ruby? – Denis de Bernardy Jun 02 '11 at 10:06
-
http://stackoverflow.com/questions/5050873/nokogiri-xml-import-feed-organisation – Denis de Bernardy Jun 02 '11 at 10:16
-
do you want the raw xml to be stored? – apneadiving Jun 02 '11 at 10:23
-
1@Aditya: Tell us more about your needs. Why do you think you need rails? The more details in the question, the more useful answers you will receive. – Arsen7 Jun 02 '11 at 10:38
-
@Arsen7 The Users will upload XML sheets and it should get stored in our database. Rails coz we have an app that runs on MySQL and Rails. Now, this XML import module should let the user import the XML data which in turn will go to the database and will be used by the app which we already built. Hope i made it clear. – Aditya Vikram Thoomati Jun 02 '11 at 15:49
1 Answers
1
Why do you need Rails for this task? Will the XML file be uploaded by users? If not, then a script in ruby may be all you need.
In all cases you need to:
- parse incoming XML and set the properties of some object or variables
- save these properties or variables in the database.
For the first task you may use ReXML, LibXML, Nokogiri or any other XML parser library.
For the second (if you don't use ActiveRecord in Rails), you may see the documentation for the mysql2 gem.
Feel free to ask further questions if you have any problems with these libraries.

Arsen7
- 12,522
- 2
- 43
- 60