Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Parsing XML with namespace in IE. (getElementsByTagNameNS())

From: Steve <stephen.joung@----------.--->
To: NULL
Date: 11/2/2008 12:08:00 PM
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=currStatement;
    var currRev=1/currRate;
    currRevFix=currRev.toFixed(5);
    var currRevStatement= "1 " + curr +"= " + currRevFix + " EUR";
    document.getElementById("rateRev").value=currRevStatement;
};


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent