MYSQL:使用LOAD XML导入XML数据文件

时间:2017-09-20 14:10:38

标签: mysql xml

我试图将一些XML格式加载到公共表结构中,并且遇到其中一个包含以下XML数据的问题:

<payslip >
  <address >
    <addressee >XXXXX YYYYY</addressee>
    <line >167 High Road</line>
    <line >Walthamstow</line>
    <line >London</line>
    <line >E17 5DD      [201567 ]</line>
    <ifundelivered >3738 XYZ Limited  Herring Court  27 - 29 Frobisher Street  Dulwich  London  WC2B 3SS</ifundelivered></address>
  <employer >
    <name >3738 XYZ Limited</name>
    <taxdistrict >406</taxdistrict>
    <taxref >LA99999</taxref></employer>
  <employee >
    <payroll >3799-</payroll>
    <userid >3799-201567</userid>
    <number >201567</number>
    <name >XXXXX YYYYY</name>
    <deptnumber >0001</deptnumber>
    <deptname >2000</deptname>
    <taxcode >1150L</taxcode>
    <NINO >QQ104330Q</NINO>
    <NItable >A</NItable>
    <email >xxxxx.yyyyy@qqqqqq.co.uk</email></employee>
  <period >
    <paydate >2017-08-11</paydate>
    <taxperiod type = "week" >20</taxperiod></period>
  <elements >
    <element amount = "1572.62" position = "gross" title = "Salary"/>
    <element amount = "-470.00" position = "adjust" title = "P.A.Y.E." ytd = "1399.80"/>
    <element amount = "1741.00" position = "gross" title = "Perf Bonus"/>
    <element amount = "-312.84" position = "adjust" title = "N.I." ytd = "994.34"/>
    <element amount = "-78.63" position = "gross" rate = "-78.6300" title = "Unpaid Sick" units = "1.0000"/>
    <element amount = "-1.00" position = "adjust" title = "RDC" ytd = "3.00"/>
  </elements>
  <totals >
    <gross >3234.99</gross>
    <adjustments >-783.84</adjustments>
    <nett >2451.15</nett></totals>
  <notations >
    <thisemployment title = "NIable Pay" ytd = "11426.14"/>
    <thisemployment title = "Taxable Pay" ytd = "11426.14"/>
    <thisemployment title = "Tax deduct." ytd = "1399.80"/>
    <prevemployment title = "Pay" ytd = "0.00"/>
    <prevemployment title = "Tax deduct." ytd = "0.00"/>
    <employer thisrun = "359.76" title = "Nat. Ins." ytd = "1143.48"/>
    <employer thisrun = "0.00" title = "Pension" ytd = "15.73"/>
  </notations>
  <comments >
    <line >2451.15 paid by BACS.  **-*7-13 A/c ****3333</line>
  </comments>
</payslip>

我无法为差异部分中的元素分配变量。例如元素&#39; name&#39;出现在&#39;员工&#39;和雇主&#39;部分和我无法区分这些部分以将变量分配给列。

LOAD XML local INFILE 'I:/PAYSLIPS37380004.xml'
INTO TABLE test.temp_payslips
    rows identified by '<payslip>'
    (@NINO,
    @number)

SET Payrollrunid=1,
    isLive=1,
    print=0,
    NINumber=@NINO,
    EmployeeNumber=@number;

我尝试在变量前加上该部分(例如@ employee.number),但这并不起作用。有什么想法吗?

我还需要根据&#39;元素中的数据在子表(paysliptrans)中创建记录。部分。我想要使​​用的代码是:

LOAD XML local INFILE 'I:/PAYSLIPS37380004.xml'
INTO TABLE pmdata_test.temp_paysliptrans rows identified by '<elements>'
    (@title,
    @amount,
    @position,
    @rate,
    @units,
    @ytd)

SET PayslipID=(select payslipid from pmdata_test.temp_payslips where EmployeeNumber=@number),
    Name=@title,
    Type="P",
    Total=@amount,
    Rate=@rate,
    Units=@units,
    YTD=@ytd;

但我仍然遇到同样的问题,因为它不会提取@number(员工),这是获取payslipID数据以填充paysliptrans.payslipID字段所必需的。

其他信息:

temp_payslips表

CREATE TABLE `temp_payslips` (
  `PayslipID` int(11) NOT NULL AUTO_INCREMENT,
  `PayrollRunID` int(11) NOT NULL,
  `EmployeeID` varchar(45) DEFAULT NULL,
  `EmployeeNumber` varchar(10) NOT NULL DEFAULT '0',
  `FirstName` varchar(45) DEFAULT NULL,
  `LastName` varchar(45) DEFAULT NULL,
  `EmployeeName` varchar(45) DEFAULT NULL,
  `AddressName` varchar(45) DEFAULT NULL,
  `Address1` varchar(45) DEFAULT NULL,
  `Address2` varchar(45) DEFAULT NULL,
  `Address3` varchar(45) DEFAULT NULL,
  `Address4` varchar(45) DEFAULT NULL,
  `Address5` varchar(45) DEFAULT NULL,
  `PostCode` varchar(45) DEFAULT NULL,
  `Country` varchar(45) DEFAULT NULL,
  `CompanyName` varchar(45) DEFAULT NULL,
  `Department` varchar(45) DEFAULT NULL,
  `CostCentre` varchar(15) DEFAULT NULL,
  `CostCentreDesc` varchar(45) DEFAULT NULL,
  `LocationName` varchar(35) DEFAULT NULL,
  `PayDate` date DEFAULT NULL,
  `PeriodNumber` int(11) DEFAULT NULL,
  `PayFrequency` varchar(10) DEFAULT NULL,
  `PayMethod` varchar(20) DEFAULT NULL,
  `PrintPayslip` varchar(1) DEFAULT NULL,
  `TaxCode` varchar(7) DEFAULT NULL,
  `TaxBasis` varchar(10) DEFAULT NULL,
  `NINumber` varchar(9) DEFAULT NULL,
  `NICode` varchar(1) DEFAULT NULL,
  `GrossPay` decimal(10,2) DEFAULT NULL,
  `GrossPayYTD` decimal(10,2) DEFAULT NULL,
  `GrossTaxPayYTD` decimal(10,2) DEFAULT NULL,
  `TaxPaidYTD` decimal(10,2) DEFAULT NULL,
  `Deductions` decimal(10,2) DEFAULT NULL,
  `DeductionsYTD` decimal(10,2) DEFAULT NULL,
  `NETPay` decimal(10,2) DEFAULT NULL,
  `NETPayYTD` decimal(10,2) DEFAULT NULL,
  `BankName` varchar(45) DEFAULT NULL,
  `BankSortCode` varchar(8) DEFAULT NULL,
  `BankAccount` varchar(8) DEFAULT NULL,
  `BuildingSocNum` varchar(45) DEFAULT NULL,
  `Message` varchar(45) DEFAULT NULL,
  `HolidayEntitlement` int(11) DEFAULT NULL,
  `HolidayTakenThisPeriod` int(11) DEFAULT NULL,
  `HolidayRemaining` int(11) DEFAULT NULL,
  `ERSPen` decimal(10,2) DEFAULT NULL,
  `OutputPrint` bit(1) DEFAULT NULL,
  `OutputEmail` varchar(255) DEFAULT NULL,
  `OutputSMS` bit(1) DEFAULT NULL,
  `OutputPortal` bit(1) DEFAULT NULL,
  `DeliveryType` varchar(45) DEFAULT NULL,
  `DeliveryGroup` varchar(45) DEFAULT NULL,
  `CompanyCode` varchar(45) DEFAULT NULL,
  `EmployerPension` decimal(10,2) DEFAULT NULL,
  `EmployerPensionYTD` decimal(10,2) DEFAULT NULL,
  `EmployeePension` decimal(10,2) DEFAULT NULL,
  `EmployeePensionYTD` decimal(10,2) DEFAULT NULL,
  `Misc1Pension` decimal(10,2) DEFAULT NULL,
  `Misc1PensionYTD` decimal(10,2) DEFAULT NULL,
  `Misc2Pension` decimal(10,2) DEFAULT NULL,
  `Misc2PensionYTD` decimal(10,2) DEFAULT NULL,
  `TaxYear` year(4) DEFAULT NULL,
  `P45GrossforTax` decimal(10,2) DEFAULT NULL,
  `P45Tax` decimal(10,2) DEFAULT NULL,
  `EmployeeNIYTD` decimal(10,2) DEFAULT NULL,
  `EmployerNI` decimal(10,2) DEFAULT NULL,
  `EmployerNIYTD` decimal(10,2) DEFAULT NULL,
  `GrossforNI` decimal(10,2) DEFAULT NULL,
  `GrossforNIYTD` decimal(10,2) DEFAULT NULL,
  `SSPYTD` decimal(10,2) DEFAULT NULL,
  `SMPYTD` decimal(10,2) DEFAULT NULL,
  `SPPYTD` decimal(10,2) DEFAULT NULL,
  `SAPYTD` decimal(10,2) DEFAULT NULL,
  `ASPPYTD` decimal(10,2) DEFAULT NULL,
  `AllSPYTD` decimal(10,2) DEFAULT NULL,
  `SortSeq` int(11) DEFAULT NULL,
  `tempId` int(11) DEFAULT NULL,
  `superceded` tinyint(4) DEFAULT '0',
  `isLive` tinyint(4) NOT NULL DEFAULT '1',
  `print` tinyint(4) NOT NULL DEFAULT '0',
  `UUID` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`PayslipID`,`PayrollRunID`,`EmployeeNumber`),
  KEY `PayDate` (`PayDate`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

temp_paysliptrans表

CREATE TABLE `temp_paysliptrans` (
  `PayslipTranID` int(11) NOT NULL AUTO_INCREMENT,
  `PayslipID` int(11) NOT NULL DEFAULT '0',
  `Name` varchar(45) DEFAULT NULL,
  `Type` varchar(1) NOT NULL DEFAULT '',
  `pstOrder` int(11) DEFAULT NULL,
  `Units` decimal(10,2) DEFAULT NULL,
  `Rate` decimal(10,4) DEFAULT NULL,
  `Total` decimal(10,2) DEFAULT NULL,
  `YTD` decimal(10,2) DEFAULT NULL,
  `Nontaxable` varchar(1) DEFAULT NULL,
  `UserDefInt1` int(11) DEFAULT NULL,
  `UserDefDec1` decimal(10,2) DEFAULT NULL,
  PRIMARY KEY (`PayslipTranID`,`PayslipID`,`Type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

1 个答案:

答案 0 :(得分:0)

可以按如下方式加载XML文件:

档案:/path/to/file/PAYSLIPS37380004.xml

<payslip>
  <address>
    <addressee>XXXXX YYYYY</addressee>
    <line>167 High Road</line>
    <line>Walthamstow</line>
    <line>London</line>
    <line>E17 5DD      [201567 ]</line>
    <ifundelivered>3738 XYZ Limited  Herring Court  27 - 29 Frobisher Street  Dulwich  London  WC2B 3SS</ifundelivered>
  </address>
  <employer>
    <name>3738 XYZ Limited</name>
    <taxdistrict>406</taxdistrict>
    <taxref>LA99999</taxref>
  </employer>
  <employee>
    <payroll>3799-</payroll>
    <userid>3799-201567</userid>
    <number>201567</number>
    <name>XXXXX YYYYY</name>
    <deptnumber>0001</deptnumber>
    <deptname>2000</deptname>
    <taxcode>1150L</taxcode>
    <NINO>QQ104330Q</NINO>
    <NItable>A</NItable>
    <email>xxxxx.yyyyy@qqqqqq.co.uk</email>
  </employee>
  <period>
    <paydate>2017-08-11</paydate>
    <taxperiod type="week">20</taxperiod>
  </period>
  <elements>
    <element amount="1572.62" position="gross" title="Salary"/>
    <element amount="-470.00" position="adjust" title="P.A.Y.E." ytd="1399.80"/>
    <element amount="1741.00" position="gross" title="Perf Bonus"/>
    <element amount="-312.84" position="adjust" title="N.I." ytd="994.34"/>
    <element amount="-78.63" position="gross" rate="-78.6300" title="Unpaid Sick" units="1.0000"/>
    <element amount="-1.00" position="adjust" title="RDC" ytd="3.00"/>
  </elements>
  <totals>
    <gross>3234.99</gross>
    <adjustments>-783.84</adjustments>
    <nett>2451.15</nett>
  </totals>
  <notations>
    <thisemployment title="NIable Pay" ytd="11426.14"/>
    <thisemployment title="Taxable Pay" ytd="11426.14"/>
    <thisemployment title="Tax deduct." ytd="1399.80"/>
    <prevemployment title="Pay" ytd="0.00"/>
    <prevemployment title="Tax deduct." ytd="0.00"/>
    <employer thisrun="359.76" title="Nat. Ins." ytd="1143.48"/>
    <employer thisrun="0.00" title="Pension" ytd="15.73"/>
  </notations>
  <comments>
    <line>2451.15 paid by BACS.  **-*7-13 A/c ****3333</line>
  </comments>
</payslip>

MySQL命令行:

mysql> SELECT VERSION();
+-----------+
| VERSION() |
+-----------+
| 5.7.19    |
+-----------+
1 row in set (0.00 sec)

mysql> DROP TABLE IF EXISTS `temp_paysliptrans`,
    ->                      `temp_payslips`;
Query OK, 0 rows affected, 2 warnings (0.00 sec)

mysql> CREATE TABLE IF NOT EXISTS `temp_payslips` (
    ->   `PayslipID` INT NOT NULL AUTO_INCREMENT,
    ->   `PayrollRunID` INT NOT NULL,
    ->   `isLive` TINYINT NOT NULL DEFAULT '1',
    ->   `print` TINYINT NOT NULL DEFAULT '0',
    ->   `EmployeeNumber` VARCHAR(10) NOT NULL DEFAULT '0',
    ->   `NINumber` VARCHAR(9) DEFAULT NULL,
    ->   PRIMARY KEY (`PayslipID`, `PayrollRunID`, `EmployeeNumber`)
    -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE TABLE IF NOT EXISTS `temp_paysliptrans` (
    ->   `PayslipTranID` INT NOT NULL AUTO_INCREMENT,
    ->   `PayslipID` INT NOT NULL DEFAULT '0',
    ->   `Name` VARCHAR(45) DEFAULT NULL,
    ->   `Type` VARCHAR(1) NOT NULL DEFAULT '',
    ->   `Total` DECIMAL(10,2) DEFAULT NULL,
    ->   `Rate` DECIMAL(10,4) DEFAULT NULL,
    ->   `Units` DECIMAL(10,2) DEFAULT NULL,
    ->   `YTD` DECIMAL(10,2) DEFAULT NULL,
    ->   PRIMARY KEY (`PayslipTranID`, `PayslipID`, `Type`)
    -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.01 sec)

mysql> LOAD XML LOCAL INFILE
    ->   '/path/to/file/PAYSLIPS37380004.xml'
    ->   INTO TABLE `temp_payslips`
    ->   ROWS IDENTIFIED BY '<employee>'
    ->   (
    ->     @`NINO`,
    ->     @`number`
    ->   )
    ->   SET `Payrollrunid` = 1,
    ->       `isLive` = 1,
    ->       `print` = 0,
    ->       `NINumber` = @`NINO`,
    ->       `EmployeeNumber` = @`number`;
Query OK, 1 row affected (0.00 sec)
Records: 1  Deleted: 0  Skipped: 0  Warnings: 0

mysql> SELECT
    ->   `PayslipID`,
    ->   `PayrollRunID`,
    ->   `isLive`,
    ->   `print`,
    ->   `EmployeeNumber`,
    ->   `NINumber`
    -> FROM
    ->   `temp_payslips`;
+-----------+--------------+--------+-------+----------------+-----------+
| PayslipID | PayrollRunID | isLive | print | EmployeeNumber | NINumber  |
+-----------+--------------+--------+-------+----------------+-----------+
|         1 |            1 |      1 |     0 | 201567         | QQ104330Q |
+-----------+--------------+--------+-------+----------------+-----------+
1 row in set (0.00 sec)

mysql> LOAD XML LOCAL INFILE
    ->   '/path/to/file/PAYSLIPS37380004.xml'
    ->   INTO TABLE `temp_paysliptrans`
    ->   ROWS IDENTIFIED BY '<element>'
    ->   (
    ->     @`title`,
    ->     @`amount`,
    ->     @`position`,
    ->     @`rate`,
    ->     @`units`,
    ->     @`ytd`
    ->   )
    ->   SET `Name` = @`title`,
    ->       `Type` = 'P',
    ->       `Total` = @`amount`,
    ->       `Rate` = @`rate`,
    ->       `Units` = @`units`,
    ->       `YTD` = @`ytd`;
Query OK, 6 rows affected (0.00 sec)
Records: 6  Deleted: 0  Skipped: 0  Warnings: 0

mysql> SELECT
    ->   `PayslipTranID`,
    ->   `PayslipID`,
    ->   `Name`,
    ->   `Type`,
    ->   `Total`,
    ->   `Rate`,
    ->   `Units`,
    ->   `YTD`
    -> FROM
    ->   `temp_paysliptrans`;
+---------------+-----------+-------------+------+---------+----------+-------+---------+
| PayslipTranID | PayslipID | Name        | Type | Total   | Rate     | Units | YTD     |
+---------------+-----------+-------------+------+---------+----------+-------+---------+
|             1 |         0 | Salary      | P    | 1572.62 |     NULL |  NULL |    NULL |
|             2 |         0 | P.A.Y.E.    | P    | -470.00 |     NULL |  NULL | 1399.80 |
|             3 |         0 | Perf Bonus  | P    | 1741.00 |     NULL |  NULL |    NULL |
|             4 |         0 | N.I.        | P    | -312.84 |     NULL |  NULL |  994.34 |
|             5 |         0 | Unpaid Sick | P    |  -78.63 | -78.6300 |  1.00 |    NULL |
|             6 |         0 | RDC         | P    |   -1.00 |     NULL |  NULL |    3.00 |
+---------------+-----------+-------------+------+---------+----------+-------+---------+
6 rows in set (0.00 sec)

但是,您的需求需要更多工作,因为您必须在PayslipID表的temp_payslips列中插入PayslipIDtemp_paysliptrans列的值,显示替代方案下面(调整你认为必要的一切):

mysql> DROP PROCEDURE IF EXISTS `insert_xml_items`;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> DROP TEMPORARY TABLE IF EXISTS `xml_items`;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> DROP TABLE IF EXISTS `temp_paysliptrans`,
     ->                      `temp_payslips`;
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE TABLE IF NOT EXISTS `temp_payslips` (
    ->   `PayslipID` INT UNSIGNED NOT NULL AUTO_INCREMENT,
    ->   `PayrollRunID` INT UNSIGNED NOT NULL,
    ->   `isLive` TINYINT NOT NULL DEFAULT '1',
    ->   `print` TINYINT NOT NULL DEFAULT '0',
    ->   `EmployeeNumber` VARCHAR(10) NOT NULL DEFAULT '0',
    ->   `NINumber` VARCHAR(9) DEFAULT NULL,
    ->   PRIMARY KEY (`PayslipID`, `PayrollRunID`, `EmployeeNumber`)
    -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
Query OK, 0 rows affected (0.01 sec)

mysql> CREATE TABLE IF NOT EXISTS `temp_paysliptrans` (
    ->   `PayslipTranID` INT UNSIGNED NOT NULL AUTO_INCREMENT,
    ->   `PayslipID` INT UNSIGNED NOT NULL DEFAULT '0',
    ->   `Name` VARCHAR(45) DEFAULT NULL,
    ->   `Type` VARCHAR(1) NOT NULL DEFAULT '',
    ->   `Total` DECIMAL(10, 2) DEFAULT NULL,
    ->   `Rate` DECIMAL(10, 4) DEFAULT NULL,
    ->   `Units` DECIMAL(10, 2) DEFAULT NULL,
    ->   `YTD` DECIMAL(10, 2) DEFAULT NULL,
    ->   PRIMARY KEY (`PayslipTranID`, `PayslipID`, `Type`)
    -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE TEMPORARY TABLE IF NOT EXISTS `xml_items` (
    ->   `id` SERIAL,
    ->   `xml_item` LONGTEXT NOT NULL
    -> ) DEFAULT CHARSET=utf8mb4;
Query OK, 0 rows affected (0.00 sec)

mysql> LOAD DATA LOCAL INFILE
    ->   '/path/to/file/PAYSLIPS37380004.xml'
    ->   INTO TABLE `xml_items`
    ->   CHARACTER SET utf8mb4
    ->   LINES TERMINATED BY '</payslip>\n'
    ->   (@`xml_item`)
    ->   SET `xml_item` = @`xml_item`;
Query OK, 1 row affected (0.00 sec)
Records: 1  Deleted: 0  Skipped: 0  Warnings: 0

mysql> UPDATE `xml_items`
    -> SET `xml_item` = CONCAT(`xml_item`, '</payslip>\n');
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> DELIMITER $$

mysql> CREATE PROCEDURE `insert_xml_items`()
    -> BEGIN
    ->   DECLARE `xml_items` INT UNSIGNED DEFAULT (SELECT COUNT(`id`)
    ->                                             FROM `xml_items`);
    ->   DECLARE `current_xml_item` LONGTEXT;
    ->   DECLARE `xml_item_elements`,
    ->           `temp_payslips_PayslipID` INT UNSIGNED;
    ->   DECLARE `index_current_xml_item`,
    ->           `index_current_xml_item_element` INT UNSIGNED DEFAULT 1;
    -> 
    ->   WHILE `index_current_xml_item` <= `xml_items` DO
    ->     SELECT `xml_item` INTO `current_xml_item`
    ->     FROM `xml_items`
    ->     WHERE `id` = `index_current_xml_item`;
    -> 
    ->     INSERT INTO `temp_payslips` (
    ->       `PayrollRunID`,
    ->       `isLive`,
    ->       `print`,
    ->       `NINumber`,
    ->       `EmployeeNumber`
    ->     ) VALUES (
    ->       1,
    ->       1,
    ->       0,
    ->       `ExtractValue`(`current_xml_item`,
    ->                      'payslip/employee/NINO'),
    ->       `ExtractValue`(`current_xml_item`,
    ->                      'payslip/employee/number')
    ->     );
    -> 
    ->     SELECT
    ->       LAST_INSERT_ID(),
    ->       `ExtractValue`(`current_xml_item`,
    ->       'COUNT(payslip/elements/element)'),
    ->       1
    ->     INTO
    ->       `temp_payslips_PayslipID`,
    ->       `xml_item_elements`,
    ->       `index_current_xml_item_element`;
    -> 
    ->     WHILE `index_current_xml_item_element` <= `xml_item_elements` DO
    ->       INSERT INTO `temp_paysliptrans` (
    ->         `PayslipID`,
    ->         `Name`,
    ->         `Type`,
    ->         `Total`,
    ->         `Rate`,
    ->         `Units`,
    ->         `YTD`
    ->       ) VALUES (
    ->         `temp_payslips_PayslipID`,
    ->         NULLIF(`ExtractValue`(`current_xml_item`,
    ->                               'payslip/elements/element[$index_current_xml_item_element]/attribute::title'),
    ->                ''),
    ->         'P',
    ->         NULLIF(`ExtractValue`(`current_xml_item`,
    ->                               'payslip/elements/element[$index_current_xml_item_element]/attribute::amount'),
    ->                ''),
    ->         NULLIF(`ExtractValue`(`current_xml_item`,
    ->                               'payslip/elements/element[$index_current_xml_item_element]/attribute::rate'),
    ->                ''),
    ->         NULLIF(`ExtractValue`(`current_xml_item`,
    ->                               'payslip/elements/element[$index_current_xml_item_element]/attribute::units'),
    ->                ''),
    ->         NULLIF(`ExtractValue`(`current_xml_item`,
    ->                               'payslip/elements/element[$index_current_xml_item_element]/attribute::ytd'),
    ->                '')
    ->       );
    ->       SET `index_current_xml_item_element` := `index_current_xml_item_element` + 1;
    ->     END WHILE;
    ->     SET `index_current_xml_item` := `index_current_xml_item` + 1;
    ->   END WHILE;
    -> END$$
Query OK, 0 rows affected (0.00 sec)

mysql> DELIMITER ;

mysql> CALL `insert_xml_items`;
Query OK, 1 row affected (0.00 sec)

mysql> SELECT
    ->   `PayslipID`,
    ->   `PayrollRunID`,
    ->   `isLive`,
    ->   `print`,
    ->   `EmployeeNumber`,
    ->   `NINumber`
    -> FROM
    ->   `temp_payslips`;
+-----------+--------------+--------+-------+----------------+-----------+
| PayslipID | PayrollRunID | isLive | print | EmployeeNumber | NINumber  |
+-----------+--------------+--------+-------+----------------+-----------+
|         1 |            1 |      1 |     0 | 201567         | QQ104330Q |
+-----------+--------------+--------+-------+----------------+-----------+
1 row in set (0.00 sec)

mysql> SELECT
    ->   `PayslipTranID`,
    ->   `PayslipID`,
    ->   `Name`,
    ->   `Type`,
    ->   `Total`,
    ->   `Rate`,
    ->   `Units`,
    ->   `YTD`
    -> FROM
    ->   `temp_paysliptrans`;
+---------------+-----------+-------------+------+---------+----------+-------+---------+
| PayslipTranID | PayslipID | Name        | Type | Total   | Rate     | Units | YTD     |
+---------------+-----------+-------------+------+---------+----------+-------+---------+
|             1 |         1 | Salary      | P    | 1572.62 |     NULL |  NULL |    NULL |
|             2 |         1 | P.A.Y.E.    | P    | -470.00 |     NULL |  NULL | 1399.80 |
|             3 |         1 | Perf Bonus  | P    | 1741.00 |     NULL |  NULL |    NULL |
|             4 |         1 | N.I.        | P    | -312.84 |     NULL |  NULL |  994.34 |
|             5 |         1 | Unpaid Sick | P    |  -78.63 | -78.6300 |  1.00 |    NULL |
|             6 |         1 | RDC         | P    |   -1.00 |     NULL |  NULL |    3.00 |
+---------------+-----------+-------------+------+---------+----------+-------+---------+
6 rows in set (0.00 sec)

mysql> DROP TEMPORARY TABLE IF EXISTS `xml_items`;
Query OK, 0 rows affected (0.00 sec)