xml code working in internet explorer only

Discussion in 'Javascript' started by mr_burns, Dec 29, 2004.

  1. mr_burns

    mr_burns Guest

    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
     
    mr_burns, Dec 29, 2004
    #1
    1. Advertising

  2. Hywel Jenkins, Dec 29, 2004
    #2
    1. Advertising

  3. 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/
     
    Martin Honnen, Dec 29, 2004
    #3
  4. mr_burns

    Mark Preston Guest

    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.
     
    Mark Preston, Dec 31, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shardool Karnik
    Replies:
    1
    Views:
    3,045
    G√ľnter Prossliner
    Aug 13, 2003
  2. Adrian Stovold
    Replies:
    0
    Views:
    369
    Adrian Stovold
    Mar 3, 2004
  3. cmay
    Replies:
    0
    Views:
    1,180
  4. Ed Hauptman
    Replies:
    7
    Views:
    1,098
    Ed Hauptman
    Aug 7, 2009
  5. John Smith
    Replies:
    1
    Views:
    174
    Evertjan.
    Mar 12, 2005
Loading...

Share This Page