This article is half-done without your Comment! *** Please share your thoughts via Comment ***
In this post, I am going to import XML file data into a table of MySQL Database.
MySQL provides LOAD XML INFILE to import XML file data into a table. We can use ROWS IDENTIFIED BY clause to read row by providing a XML node.
It supports three different type of XML formats.
1 |
1 2 3 4 |
1 2 3 4 |
Note: Table column name and XML column or tag name should be same otherwise it will not insert into a table.
Below is a small demonstration of this:
First, Create a sample XML file:
Name of this file is Employee.xml and I have saved in my local drive.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
Create a sample table:
1 2 3 4 5 6 |
CREATE TABLE tbl_Employees ( EmpID INTEGER PRIMARY KEY ,EmpFirstName VARCHAR(50) ,EmpLastName VARCHAR(50) ); |
Import XML Data into a table:
1 2 3 |
LOAD XML LOCAL INFILE 'E:/Employee.xml' INTO TABLE tbl_Employees ROWS IDENTIFIED BY ' |
Check the table:
1 |
SELECT *FROM tbl_Employees; |
Leave a Reply