問題描述
我想構(gòu)建一個 Rails 應(yīng)用程序來將數(shù)據(jù)從 XML 文件導(dǎo)入到 MySQL 數(shù)據(jù)庫中.有什么幫助嗎?
I would like to build a Rails application to import the data from a XML file into a MySQL database. Any help?
推薦答案
為什么需要 Rails 來完成這個任務(wù)?XML 文件會被用戶上傳嗎?如果沒有,那么您可能只需要一個 ruby?? 腳本.
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:
- 解析傳入的 XML 并設(shè)置某些對象或變量的屬性
- 將這些屬性或變量保存在數(shù)據(jù)庫中.
對于第一個任務(wù),您可以使用 ReXML,LibXML,Nokogiri 或任何其他 XML 解析器庫.
For the first task you may use ReXML, LibXML, Nokogiri or any other XML parser library.
對于第二個(如果您不在 Rails 中使用 ActiveRecord),您可能會看到 mysql2 gem 的文檔.
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.
這篇關(guān)于將數(shù)據(jù)從 XML 文件導(dǎo)入 MySQL 數(shù)據(jù)庫的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!