loop in simplexml load file
- by shantanuo
I am using the following code to parse the XML data to MySQL table and it is working as expected.
<?php
$sxe = simplexml_load_file("$myfile");
foreach($sxe->AUTHAD as $sales) {
$authad="insert into test.authad values ('".mysql_real_escape_string($sales->LOCALDATE)."','".mysql_real_escape_string($sales->LOCALTIME)."','".mysql_real_escape_string($sales->TLOGID)."','" ...
?>
The problem is that when I get a new xml file with different format, I can not use the above insert into statement and have to change the parameters manually. For e.g.
$authadv_new="insert into test.authad values ('".mysql_real_escape_string($sales->NEW1)."','".mysql_real_escape_string($sales->NEW2)."','".mysql_real_escape_string($sales->NEW3)."','" ...
Is there any way to automate this? I mean the PHP code should be able to anticipate the parameters and generate the mysql_real_escape_string($sales-NEW1) to NEW10 values using a loop.