解析xml文件并将其存储到数据库中 [英] Parsing an xml file and storing it into a database

查看:485
本文介绍了解析xml文件并将其存储到数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在R或python中是否有通用/自动的方式来解析带有节点和属性的xml文件,自动生成用于存储该信息的mysql表,然后填充这些表.

Is there a generic/automatic way in R or in python to parse xml files with its nodes and attributes, automatically generate mysql tables for storing that information and then populate those tables.

推荐答案

关于

R中是否有通用/自动方式 解析XML文件及其节点,并 属性,自动生成 mysql表用于存储 信息,然后填充这些 桌子.

Is there a generic/automatic way in R to parse xml files with its nodes and attributes, automatically generate mysql tables for storing that information and then populate those tables.

答案很老了,至少在 R .

the answer is a good old yes you can, at least in R.

R的 XML 包可以读取XML文档并返回R data.frame类型使用xmlToDataFrame()函数在一个呼叫中.

The XML package for R can read XML documents and return R data.frame types in a single call using the xmlToDataFrame() function.

RMySQL 包可以将data.frame对象传输到数据库 中的一个命令-如果需要,包括创建表的功能-使用常见的dbWriteTable()函数"rel =" noreferrer> DBI 后端,用于R,由RMySQL .

And the RMySQL package can transfer data.frame objects to the database in a single command---including table creation if need be---using the dbWriteTable() function defined in the common DBI backend for R and provided for MySQL by RMySQL.

简而言之:两行就可以做到,因此您可以轻松地编写一个新的帮助程序函数来完成此任务,同时还要进行相当数量的错误检查.

So in short: two lines can do it, so you can easily write yourself a new helper function that does it along with a commensurate amount of error checking.

这篇关于解析xml文件并将其存储到数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆