<?php
$link = mysql_connect('localhost','root','root');
mysql_select_db('test');
$result = mysql_query("SELECT * FROM `tbl_test`");

header('Content-type: text/xml');
header('Pragma: public');
header('Cache-control: private');
header('Expires: -1');

$xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
$xml.= "<users>";

while($row1 = mysql_fetch_array($result)) {

$xml.= " <user>";
$xml.= " <firstname>".$row1['fname']."</firstname>";
$xml.= " <lastname>".$row1['lname']."</lastname>";
$xml.= " <Mobile>".$row1['mno']."</Mobile>";
$xml.= " <date>".$row1['date_added']."</date>";
$xml.= " </user>";

}

$xml.= "</users>";
$fh = fopen(time().'.xml', 'w+');
fwrite($fh, $xml);
fclose($fh);
?>
read xml data and insert into database        

$xml = simplexml_load_file("1353663817.xml");
$aa = "";
foreach($xml->children() as $child)
{
foreach($child->children() as $childs)
{
$aa .= "'".$childs ."',";
}

$aa = substr_replace($aa, "", -1);

echo $sql = "INSERT into tbl_xmldata (person_id,first_name,last_name) values ( $aa )";
}
Advertisements