Hi all friends,
I am trying to insert XML data using DOM, i completed mostly but little bit left, issue in the <field></field> the data between that not inserted in db, please consider the below mentioned XML file...
<?xml version="1.0" encoding="UTF-8"?>
<form name="mc1.dpp" application-name="mc1.dpp" application-id="34" document-id="1342" producer="Penvision Formidable Application Server" export-time="2012-11-13T12:04:32+04:00" first-page="86.658.2.129" last-page="86.658.2.129">
<submit email="123@abc.com"/>
<field type="textfield" name="learningpermitno" normalized-score="1" resemblance-score="0.239">LOO4</field>
<field type="textfield" name="applicantname" normalized-score="1" resemblance-score="0.627">Kaifi</field>
<userinfo>
<penid>AJX-AAQ-JFN-5Z</penid>
<email>123@abc.com</email>
<phone>123456</phone>
<firststroke>1352793331</firststroke>
</userinfo>
</form>
PHP Code:
<?php
$oDOM = new DOMDocument();
$oDOM->loadXML(file_get_contents('xmlfile.xml')); #See: http://msdn.microsoft.com/en-us/library/ms762271(VS.85).aspx
foreach ($oDOM->getElementsByTagName('form') as $oBookNode)
{
$sSQL = sprintf(
"INSERT INTO timestamp_table (learningpermit, applicantname, penid, email, phone,firststroke) VALUES ('%s', '%s', '%s', '%s', '%s', '%s')",
mysql_real_escape_string($oBookNode->getElementsByTagName('field')->item(0)->nodeValue),
mysql_real_escape_string($oBookNode->getElementsByTagName('field')->item(0)->nodeValue),
mysql_real_escape_string($oBookNode->getElementsByTagName('penid')->item(0)->nodeValue),
mysql_real_escape_string($oBookNode->getElementsByTagName('email')->item(0)->nodeValue),
mysql_real_escape_string($oBookNode->getElementsByTagName('phone')->item(0)->nodeValue),
mysql_real_escape_string($oBookNode->getElementsByTagName('firststroke')->item(0)->nodeValue)
);
$rResult = mysql_query($sSQL);
?>
--
Kind Regards