I am trying to import a XML file into a MySQL database and I am having some issues along the way. This is the code that I have so far:
function convertXML($node){
foreach($node->Body->Cube as $child)
{
echo $child['date'] .",";
foreach($child->Rate as $child1)
{
echo $response=$child1 . ",";
}
echo "<br>";
//mysql_query("INSERT INTO table ('date', 'AED', 'AUD', 'BGN', 'BRL') VALUES $response");
}
}
$row = convertXML($xml);
And this is a sample of my XML file:
<DataSet>
<Header>
<PublishingDate>2012-12-04</PublishingDate>
<MessageType>DR</MessageType>
</Header>
<Body>
<Subject>Reference</Subject>
<OrigCurrency>RO</OrigCurrency>
<Cube date="2012-12-03">
<Rate currency="AED">0.9439</Rate>
<Rate currency="AUD">3.6275</Rate>
.....
<Rate currency="BGN">2.3170</Rate>
</Cube>
<Cube date="2012-12-04">
<Rate currency="AED">0.93129</Rate>
<Rate currency="AUD">3.3576</Rate>
....
<Rate currency="BGN">2.245/Rate>
</Cube>
</Body>
</DataSet>
I can get the results that I am interested (date and the numeric value from the RAte currency child) and print them on the screen but I am having a hard time introducing them into the database. Any help will be greatly appreciated ...