With the help of this newsgroup and Google I have got this code
working fully in Firefox and can alert the XML in IE but because IE
does not impliment the DOM "getElementsByTagNameNS()" function I
cannot read the individual rates from the Cube namespace.
Is there a wrapper or some other relatively simple method of getting
IE to do what in Firefox is straighforward?
Here is the code. Any help gratefully received.
var doc
function load() {
if (document.implementation &&
document.implementation.createDocument){
doc = document.implementation.createDocument("", "", null);
doc.load('CEBrates.xml');
doc.onload = createTable;
}
else if (window.ActiveXObject){
var doc1 = new ActiveXObject("Microsoft.XMLDOM");
function loadXML(xmlFile){
doc1.async="false";
doc1.onreadystatechange=verify;
doc1.load(xmlFile);
doc=doc1.documentElement;
}
loadXML('CEBrates.xml');
alert(doc.xml)
}
else {
alert('Your browser can\'t handle this script');
return;
}
}
function verify() {
if (doc1.readyState != 4 ){
return false;
}
}
function createTable() {
var cubes = doc.getElementsByTagNameNS('http://www.ecb.int/
vocabulary/2002-08-01/eurofxref','Cube');
var dateRate = cubes[1].getAttribute('time');
var dateRateSplit = dateRate.split('-');
for (var i = 2; i < cubes.length; i++){
var currency = cubes[i].getAttribute('currency');
var rate = cubes[i].getAttribute('rate');
rateObject[currency] = rate;
}
document.getElementById('boldStuff').innerHTML = dateRateSplit[2]
+ "." + dateRateSplit[1] + "." + dateRateSplit[0];
document.getElementById("currency").value = "GBP";
getRates();
};
var rateObject = {};
function getRates() {
var curr= document.getElementById("currency").value;
var currRate = rateObject[curr];
var currStatement= "1 EUR = " + currRate + " " + curr ;
document.getElementById("rate").value=currStatemen t;
var currRev=1/currRate;
currRevFix=currRev.toFixed(5);
var currRevStatement= "1 " + curr +"= " + currRevFix + " EUR";
document.getElementById("rateRev").value=currRevSt atement;
};