473,405 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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

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;
};
Nov 2 '08 #1
1 3599
"Steve" <st***********@googlemail.comwrote in message
news:8e**********************************@p31g2000 prf.googlegroups.com...
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?
You could always use XPath instead.
Instead of "Microsoft.XMLDOM" use "MSXML2.DomDocument.3.0".
The set the SelectionLanguage
doc1.setProperty("SelectionLanguage", "XPath")
then the namespace prefix:
doc1.setProperty("SelectionNamespaces", "xmlns:df = ''http://www.ecb.int/
vocabulary/2002-08-01/eurofxref'");

Then use XPath:
var cubes = doc1.selectNodes(<xpath expression here>);
If you show the XML I can tell you the XPath :)

--

Joe Fawcett (MVP - XML)

http://joe.fawcett.name
Nov 4 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Mike McGavin | last post by:
Hi everyone. I've been trying for several hours now to get minidom to parse namespaces properly from my stream of XML, so that I can use DOM methods such as getElementsByTagNameNS(). For some...
4
by: VK | last post by:
I have this code failing to work in IE: getElementsByTagName doesn't return elements from my JS namespace. What's wrong? <html xmlns:js> <head> <title>Que</title> <meta...
7
by: kashaziz | last post by:
Hello, I am here after head-banging with this issue for several days. I am trying to parse a feed using JS and have stucked on the <content:encoded> tag. I have tried getElementsbyTagName but...
2
by: Learner | last post by:
When I execute this script with the xml document placed below it . It fails. Can Anyonw tell me the cause of it. var root=xmlDoc.documentElement var temp8 =...
7
by: Mag Gam | last post by:
I have a file similar to this: <Customer xmlns="http://www.localsite.com/ecommerce/2006-v01/ organization"> <ns1:Contract xmlns:ns1="http://www.localsite.com/ecommerce/2006-v01/ portfolio">...
6
by: jackwootton | last post by:
Hello everyone, I understand that XML can be parsed using JavaScript using the XML Document object. However, it is possible to parse XHTML using JavaScript? I currently listen for DOMMutation...
2
by: nicky123 | last post by:
Hi everyone, This is a brief description that I have provided for parsing & displaying an XML document using DOM API. Please feel free to post your own comments & views regarding...
3
by: Martin Honnen | last post by:
Steve wrote: Well saying you use JavaScript does not tell us much. Which application (e.g. which browser) provides the host environment? If it is a browser which provides the host environment,...
20
by: Steve | last post by:
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.