Results 1 to 4 of 4

Thread: Trying to convert XML to relational database file

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    523

    Trying to convert XML to relational database file

    I have an XML file that has multi-value fields. I am trying to convert this file to a relational database without success. The various techniques I have tried (reading the file directly into SQL Server & Access) both capture the structure but does not populate the data.

    An option I am considering is to write some code to parse the XML file and generate the relational file. This raises a questions.

    1) Does anyone have any suggestions, tips or know of sample code, possible with System.xml?

    Any guidance would be appreciated.

  2. #2
    Addicted Member
    Join Date
    May 2017
    Location
    Italy
    Posts
    170

    Re: Trying to convert XML to relational database file

    Do you want create a new database or export xml to a table of existing database ?

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    523

    Re: Trying to convert XML to relational database file

    Create a new one. Ideally I would like a system that would extract the structure from the xml file and create the database structure, then populate the tables with the data. As I indicated, doing a straight import to either Access or SQL Server appears to create the database structure, so I guess I could create the structure that way then import to that structure. An all in one procedure would be preferred.

  4. #4
    Fanatic Member kpmc's Avatar
    Join Date
    Sep 2017
    Posts
    1,012

    Re: Trying to convert XML to relational database file

    First I would read the XML into a dataset/table. from there iterate the columns and generate a CREATE TABLE sql command and run it. Once the table is created I would then bind a datatable to the newly created SQL table including a bindingsource. I would then iterate all the rows in the XML datatable and .addnew to the SQL bindingsource. You could also .merge the data from XML datatable to the SQL datatable but then you need to alter the rowstate of each row before a final adapter .update is called (adding the rows to the bindingsource prevents that).

    If you want to take this route then create a form, drag a datagridview and a button. Run this from the button and hopefully the XML doesnt need work to get it into the datatable

    Code:
        Private Sub ExportToSQLTable_Click(sender As Object, e As EventArgs) Handles ExportToSQLTable.Click
            Dim DS As New DataSet
            Dim XMLPath As String = "C:\DATA\XML\MgrData.XML"
            If IO.File.Exists(XMLPath) Then
                DS.ReadXml(XMLPath, XmlReadMode.InferSchema)
            End If
        End Sub

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width