By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,253 Members | 1,652 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,253 IT Pros & Developers. It's quick & easy.

xml code working in internet explorer only

P: n/a
hi,

i am using the following code which works well in internet explorer
but not in firefox (and perhaps others too):

var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.load("xml/names.xml");
nodes = xmlDoc.documentElement.childNodes
span_html = '<p>'
for (var i=0; i<nodes.length; i++) {
name = nodes.item(i).firstChild.text
span_html += 'name: '+name+'<br>';
}
span_html += '</p>';
can anybody tell me another way of writting this so it will work in
other browsers or better yet, so it will work in other browsers and
internet explorer? cheers

burnsy
Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
In article <65**************************@posting.google.com >,
bi******@yahoo.co.uk says...
hi,

i am using the following code which works well in internet explorer
but not in firefox (and perhaps others too):


You're using MS extensions to JavaScript.

http://www.sitepoint.com/article/xml-javascript-mozilla

--
Hywel http://kibo.org.uk/
I do not eat quiche.
Jul 23 '05 #2

P: n/a


mr_burns wrote:

i am using the following code which works well in internet explorer
but not in firefox (and perhaps others too):

var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
That stuff with ActiveXObject is geared towards IE/Win, it doesn't work
with Mozilla or Firefox or Opera, not even with IE/Mac.

If you want to load an XML document with Mozilla or with Opera 7.60
preview or 8.00 beta or with Safari 1.2 then you can use the
XMLHttpRequest object which is modelled after the Microsoft.XMLHTTP
object of MSXML.
Details are here:
<http://www.faqts.com/knowledge_base/view.phtml/aid/17226/fid/616>
<http://jibbering.com/2002/4/httprequest.html>
name = nodes.item(i).firstChild.text


But note that text is not a property in the W3C DOM that Mozilla or
Opera implement, for a text node the nodeValue might give you what you
want, if you are looking at element nodes then you need to write a
function to collect the text of child nodes.
With DOM Level 3 there is the textContent property too, recent Mozilla
versions implement that but not Opera as far as I know.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #3

P: n/a
mr_burns wrote:
i am using the following code which works well in internet explorer
but not in firefox (and perhaps others too):
Definately in others as well. Konqueror for example will do nothing with
this code.
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
See those magic words: "ActiveXObject" and "Microsoft"... they are
synonymous. You get ActiveX with Microsoft and Microsot supplies
Microsoft. Firefox isn't Microsoft.
can anybody tell me another way of writting this so it will work in
other browsers or better yet, so it will work in other browsers and
internet explorer? cheers


Yup - you'll find lots of code (try SourceForge) that offers examples.
There are, basically, three standard ways of getting at XML data and the
one you want to use depends on what you want to do with the XML.
Unfortunately, the method you have used is not one of the three.
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.