loop in simplexml load file
Posted
by
shantanuo
on Stack Overflow
See other posts from Stack Overflow
or by shantanuo
Published on 2011-03-11T08:25:46Z
Indexed on
2011/03/16
0:10 UTC
Read the original article
Hit count: 189
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.
© Stack Overflow or respective owner