xml code working in internet explorer only

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mr_burns

    xml code working in internet explorer only

    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.XMLDO M");
    xmlDoc.async="f alse";
    xmlDoc.load("xm l/names.xml");
    nodes = xmlDoc.document Element.childNo des
    span_html = '<p>'
    for (var i=0; i<nodes.length ; i++) {
    name = nodes.item(i).f irstChild.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
  • Hywel Jenkins

    #2
    Re: xml code working in internet explorer only

    In article <651c6ea9.04122 91003.1501e1d9@ posting.google. com>,
    bissatch@yahoo. co.uk says...[color=blue]
    > hi,
    >
    > i am using the following code which works well in internet explorer
    > but not in firefox (and perhaps others too):[/color]

    You're using MS extensions to JavaScript.



    --
    Hywel http://kibo.org.uk/
    I do not eat quiche.

    Comment

    • Martin Honnen

      #3
      Re: xml code working in internet explorer only



      mr_burns wrote:

      [color=blue]
      > 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.XMLDO M");[/color]

      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.XMLHT TP
      object of MSXML.
      Details are here:
      <http://www.faqts.com/knowledge_base/view.phtml/aid/17226/fid/616>
      <http://jibbering.com/2002/4/httprequest.htm l>
      [color=blue]
      > name = nodes.item(i).f irstChild.text[/color]

      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

      Comment

      • Mark Preston

        #4
        Re: xml code working in internet explorer only

        mr_burns wrote:
        [color=blue]
        > i am using the following code which works well in internet explorer
        > but not in firefox (and perhaps others too):[/color]

        Definately in others as well. Konqueror for example will do nothing with
        this code.
        [color=blue]
        > var xmlDoc = new ActiveXObject(" Microsoft.XMLDO M");[/color]

        See those magic words: "ActiveXObj ect" and "Microsoft" ... they are
        synonymous. You get ActiveX with Microsoft and Microsot supplies
        Microsoft. Firefox isn't Microsoft.
        [color=blue]
        > 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[/color]

        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.

        Comment

        Working...