Results 1 to 2 of 2

Thread: Need help trying to load XML page with Javascript

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    1

    Need help trying to load XML page with Javascript

    Hello everyone. I have an XML page I'm trying to load with javascript to display on Firefox. I can get this to work on Internet Explorer but it would not work on Firefox. I can't figure out what I'm doing wrong. Can someone glance at my short piece of code below and tell me why this wouldn't work on firefox? Thanks. (The XML page is listed below the HTML portion).

    Code:
    <html>
    <head>
    
    <script language="JavaScript" for="window" event="onload">
    
    var xmlDoc;
     if (window.ActiveXObject) //this portion is meant for I.E.
     {
        xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
     }
    else if (document.implementation && document.implementation.createDocument) //for firefox
    {
        xmlDoc = document.implementation.createDocument("", "doc", null);
    }
    
    xmlDoc.async="false"
    xmlDoc.load("note.xml")
    nodes = xmlDoc.documentElement.childNodes
    to.innerText = nodes.item(0).text
    from.innerText = nodes.item(1).text
    header.innerText = nodes.item(2).text
    body.innerText = nodes.item(3).text
    
    </script>
    
    <title>HTML using XML data</title>
    </head>
    
    <body bgcolor="yellow">
    <h1>Refsnes Data Internal Note</h1>
    
    <b>To: </b><span id="to"></span>
    
    <br>
    <b>From: </b><span id="from"></span>
    
    <hr>
    <b><span id="header"></span></b>
    
    <hr>
    <span id="body"></span>
    
    </body>
    </html>
    -------------------------(node.xml below)
    <note>
       <to>Tove</to>
       <from>Jani</from>
       <heading>Reminder</heading>
       <body>Don't forget me this weekend!</body>
    </note>

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    innerText is not supported by FireFox, I think that's your main problem. I'm not sure if text is supported either. Take a look at the official DOM2 reference to see what you can use.

    http://www.w3.org/
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width