xml code working in internet explorer only

M

mr_burns

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
 
M

Martin Honnen

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>
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.
 
M

Mark Preston

mr_burns said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top