Forum Moderators: coopster
<?xml version="1.0" encoding="UTF-8"?>
<gesmes:Envelope xmlns:gesmes="http://www.gesmes.org/xml/2002-08-01" xmlns="http://www.ecb.int/vocabulary/2002-08-01/eurofxref">
<gesmes:subject>Reference rates</gesmes:subject>
<gesmes:Sender>
<gesmes:name>European Central Bank</gesmes:name>
</gesmes:Sender>
<Cube>
<Cube time='2004-03-11'>
<Cube currency='USD' rate='1.2256'/>
<Cube currency='JPY' rate='135.58'/>
<Cube currency='DKK' rate='7.4518'/>
....
<Cube currency='ZAR' rate='8.2441'/>
</Cube>
</Cube>
</gesmes:Envelope>
I've done extensive searching in all known forums, but didn't find how to write the php code to do the parsing of this kind of file.
What I want to do is to check first the date, to avoid having twice the same entry, and if not yet in DB, insert the new values in the mysql table.
Now all the last part I can write, but not the parsing of the "cube" thing...
Has anyone already tried this one?
Since this is a free resource, perhaps you'll allow me to post also the URI for the XML file:
[ecb.int...]
Thanx for any suggestion.
Notawiz
For "classic" xml, things work not too bad with the tools we have in PHP, when we have <openingTag>some string</closingTag>.
But when you look at the file of the EBC, one founds all kind of stuff inside similar "Cube" tags, like the time for the first one, and then currency and rate.
I understand that the author of that file wants to have something like an array called "time", with keys called "currency" and values called "rate".
How to reconstruct a classical php array from these "cube" data, that's my problem.
Thanx.
Notawiz
[webmasterworld.com...]
...for PHP code to extract an exchange rate from the ECB feed.
So if I want to store all the rates of the ECB file, I just have to walk through the file by changing the:
$EUR_GBP_RATE = $xp->getAttributes("//Cube[@currency='GBP']","rate");
into say:
$EUR_USD_RATE = $xp->getAttributes("//Cube[@currency='USD']","rate");
and at the end store the whole bunch in my DB.
Great help!
Thanx.
Notawiz