Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automated way to convert XML files to SQL database? [closed]

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

<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?

like image 607
Steve Bennett Avatar asked Dec 12 '12 05:12

Steve Bennett


People also ask

Can SQL read XML?

Now as I said before, XML data stored in a column of data type XML can be processed either by using XML functions available in SQL Server or by using the sp_xml_preparedocument stored procedure along with the OPENXML function.

How do I get data from XML format in SQL Server?

SQL Server lets you retrieve data as XML by supporting the FOR XML clause, which can be included as part of your query. You can use the FOR XML clause in the main (outer) query as well as in subqueries. The clause supports numerous options that let you define the format of the XML data.

Can you use a XML file as a database?

XML Database is used to store huge amount of information in the XML format. As the use of XML is increasing in every field, it is required to have a secured place to store the XML documents. The data stored in the database can be queried using XQuery, serialized, and exported into a desired format.


1 Answers

For Mysql please see the 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:

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

There is also a related question:

  • How to import XMl file into MySQL database table using XML_LOAD(); function

For Postgresql I do not know.

like image 129
hakre Avatar answered Oct 12 '22 12:10

hakre