xml code working in internet explorer only

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

  1. mr_burns

    mr_burns Guest


    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");
    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

    mr_burns, Dec 29, 2004
    1. Advertisements

  2. Hywel Jenkins, Dec 29, 2004
    1. Advertisements

  3. mr_burns wrote:

    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:
    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, Dec 29, 2004
  4. mr_burns

    Mark Preston Guest

    Definately in others as well. Konqueror for example will do nothing with
    this code.
    See those magic words: "ActiveXObject" and "Microsoft"... they are
    synonymous. You get ActiveX with Microsoft and Microsot supplies
    Microsoft. Firefox isn't Microsoft.
    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
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.