Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > xml code working in internet explorer only

Reply
Thread Tools

xml code working in internet explorer only

 
 
mr_burns
Guest
Posts: n/a
 
      12-29-2004
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
 
Reply With Quote
 
 
 
 
Hywel Jenkins
Guest
Posts: n/a
 
      12-29-2004
In article <(E-Mail Removed) >,
http://www.velocityreviews.com/forums/(E-Mail Removed) 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.
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      12-29-2004


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/
 
Reply With Quote
 
Mark Preston
Guest
Posts: n/a
 
      12-31-2004
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Internet Explorer 8: C:\Program Files\Internet Explorer\iexplore.exe vs C:\Program Files (x86)\Internet Explorer\iexplore.exe Nathan Sokalski Windows 64bit 16 02-22-2010 08:31 AM
code displays PDF directly from Windows explorer but not when called by II6 to Internet explorer Ed Hauptman HTML 7 08-07-2009 10:11 PM
internet explorer 7 - Internet Explorer cannot display the webpag sandy j Windows 64bit 0 05-02-2009 02:12 AM
AOL working, Internet Explorer not working Paul Welch Computer Support 3 08-12-2006 11:29 PM
Internet Browser (Internet Explorer) Not Working MICHAEL SMITH Computer Support 12 04-22-2006 03:43 AM



Advertisments