将数据从 XML 文件导入 MySQL 数据库

2021-10-01 00:00:00 xml ruby-on-rails mysql

我想构建一个 Rails 应用程序来将数据从 XML 文件导入到 MySQL 数据库中.有什么帮助吗?

I would like to build a Rails application to import the data from a XML file into a MySQL database. Any help?

推荐答案

为什么需要 Rails 来完成这个任务?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 并设置某些对象或变量的属性
  • 将这些属性或变量保存在数据库中.

对于第一个任务,您可以使用 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.

相关文章