我正在尝试将 XML 文件导入 MySQL 数据库,但在此过程中遇到了一些问题。这是我到目前为止的代码:
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);
这是我的 XML 文件的示例:
<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>
我可以获得我感兴趣的结果(日期和来自 RAte 货币子项的数值)并将它们打印在屏幕上,但我很难将它们引入数据库。任何帮助将不胜感激 ...