问题描述
在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 .
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文件并将其存储到数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!