This question already has an answer here:
I want to insert the following XML file into a Mysql database using php
<?xml version="1.0" encoding="UTF-8"?>
<PrintLetterBarcodeData
uid="725733706873"
name="RAVINDER KUMAR"
gender="M"
yob="1996"
co="S/O KAKA RAM"
house="460A"
street="WARD NO. 6"
lm="NA"
loc="NA"
vtc="Nanyola (292)"
po="Naneola"
dist="Ambala"
state="Haryana"
pc="134003"
/>
How do I extract the data from this XML file to insert them into a database ?
</div>
For the PHP approach, you will find the following useful:
<?php
$string = <<<XML
<PrintLetterBarcodeData
uid="725733706873"
name="RAVINDER KUMAR"
gender="M"
yob="1996"
co="S/O KAKA RAM"
house="460A"
street="WARD NO. 6"
lm="NA"
loc="NA"
vtc="Nanyola (292)"
po="Naneola"
dist="Ambala"
state="Haryana"
pc="134003"
/>
XML;
$xml = simplexml_load_string($string);
$attribs = $xml->attributes();
// convert the '$attribs' to an array
foreach($attribs as $key=>$val) {
$arrayOfAttribs[(string)$key] = "'".(string)$val."'";
}
$namesOfColumns = implode(",", array_keys($arrayOfAttribs));
$valuesOfColumns = implode(",", array_values($arrayOfAttribs));
// your database stuff
$query = "INSERT INTO yourtable ($namesOfColumns) VALUES ($valuesOfColumns);";
?>