将XML文件转换成SQL数据库的自动化方法?

时间:2022-10-17 14:36:38

We have a bunch of XML files, following a schema which is essentially a serialised database form:

我们有一堆XML文件,遵循的模式本质上是一个序列化的数据库表单:

<table1>
   <column1>value</column1>
   <column2>value</column2>
</table1>
<table1>
   <column1>another value</column1>
   <column2>another value</column2>
</table1>
...

Is there a really easy way to turn that into an SQL database? Obviously I can manually construct the schema, identify all tables, fields etc, and then write a script to import it. I just wonder if there are any tools that could automate some or all of that process?

是否有一种简单的方法将其转换为SQL数据库?显然,我可以手工构建模式,识别所有的表、字段等等,然后编写一个脚本来导入它。我只是想知道是否有什么工具可以使这个过程自动化?

4 个解决方案

#1


12  

For Mysql please see the LOAD XML SyntaxDocs.

关于Mysql,请参阅LOAD XML SyntaxDocs。

It should work without any additional XML transformation for the XML you've provided, just specify the format and define the table inside the database firsthand with matching column names:

它应该对所提供的XML没有任何额外的XML转换,只需指定格式,并通过匹配的列名直接在数据库中定义表:

LOAD XML LOCAL INFILE 'table1.xml'
    INTO TABLE table1
    ROWS IDENTIFIED BY '<table1>';

There is also a related question:

还有一个相关的问题:

For Postgresql I do not know.

对于Postgresql,我不知道。

#2


2  

If there is XML file with 2 different tables then will:

如果有两个不同表的XML文件,则会:

LOAD XML LOCAL INFILE 'table1.xml' INTO TABLE table1 
LOAD XML LOCAL INFILE 'table1.xml' INTO TABLE table2

work

工作

#3


1  

There is a project on CodeProject that makes it simple to convert an XML file to SQL Script. It uses XSLT. You could probably modify it to generate the DDL too.

在CodeProject上有一个项目,它使得将XML文件转换成SQL脚本变得简单。它使用XSLT。您也可以修改它来生成DDL。

And See this question too : Generating SQL using XML and XSLT

还可以看到这个问题:使用XML和XSLT生成SQL

#4


0  

try this

试试这个

http://www.ehow.com/how_6613143_convert-xml-code-sql.html

http://www.ehow.com/how_6613143_convert-xml-code-sql.html

for downloading the tool http://www.xml-converter.com/

下载工具http://www.xml-converter.com/

#1


12  

For Mysql please see the LOAD XML SyntaxDocs.

关于Mysql,请参阅LOAD XML SyntaxDocs。

It should work without any additional XML transformation for the XML you've provided, just specify the format and define the table inside the database firsthand with matching column names:

它应该对所提供的XML没有任何额外的XML转换,只需指定格式,并通过匹配的列名直接在数据库中定义表:

LOAD XML LOCAL INFILE 'table1.xml'
    INTO TABLE table1
    ROWS IDENTIFIED BY '<table1>';

There is also a related question:

还有一个相关的问题:

For Postgresql I do not know.

对于Postgresql,我不知道。

#2


2  

If there is XML file with 2 different tables then will:

如果有两个不同表的XML文件,则会:

LOAD XML LOCAL INFILE 'table1.xml' INTO TABLE table1 
LOAD XML LOCAL INFILE 'table1.xml' INTO TABLE table2

work

工作

#3


1  

There is a project on CodeProject that makes it simple to convert an XML file to SQL Script. It uses XSLT. You could probably modify it to generate the DDL too.

在CodeProject上有一个项目,它使得将XML文件转换成SQL脚本变得简单。它使用XSLT。您也可以修改它来生成DDL。

And See this question too : Generating SQL using XML and XSLT

还可以看到这个问题:使用XML和XSLT生成SQL

#4


0  

try this

试试这个

http://www.ehow.com/how_6613143_convert-xml-code-sql.html

http://www.ehow.com/how_6613143_convert-xml-code-sql.html

for downloading the tool http://www.xml-converter.com/

下载工具http://www.xml-converter.com/