WEB JavaScript loading XML into an array.. halp.

Discussion in 'OT Technology' started by Insert Tokens, Oct 12, 2009.

  1. Insert Tokens

    Insert Tokens Making Cancer My Bitch OT Supporter

    Joined:
    Jan 12, 2006
    Messages:
    8,314
    Likes Received:
    70
    Location:
    Tasmania
    I have an XML file:

    Code:
    <items>
    <item>An item.</item>
    <item>Another item.</item>
    </items>
    
    And this script:

    Code:
    function readXML()
        {
             // code for IE
             if (window.ActiveXObject)
             {
                    alert ('IE')
                               var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
                               xmlDoc.async = false;
                               xmlDoc.load("xmlfile.xml");
             }
             // code for Mozilla, etc.
             else if (document.implementation && document.implementation.createDocument)
             {
                    alert ('FF')
                                    var xmlDoc = document.implementation.createDocument("", "", null);
                                    xmlDoc.async = false;
                                    xmlDoc.load("xmlfile.xml");
             }
             else
             {
                  alert('Your browser cannot handle this script');
             }
                  var items = xmlDoc.getElementsByTagName('item');
                  for (i=0; i < items.length; i++)
                        {
                            itemsarray[i] = items[i].firstChild.nodeValue;
                            alert(itemsarray[i]);
                        }
        }
        
    readXML();
    
    What am I doing wrong? :sadwavey:
     
  2. ge0

    ge0 New Member

    Joined:
    Oct 31, 2005
    Messages:
    8,398
    Likes Received:
    0
    Location:
    JERSEY
    See if you can find a XML to JSOn script.
     
  3. Insert Tokens

    Insert Tokens Making Cancer My Bitch OT Supporter

    Joined:
    Jan 12, 2006
    Messages:
    8,314
    Likes Received:
    70
    Location:
    Tasmania
    Ack, this AJAX shit is over my head :rofl:

    Just trying to get a basic XML file into a JS array..

    Will look up some more AJAX tuts I guess.
     
  4. Insert Tokens

    Insert Tokens Making Cancer My Bitch OT Supporter

    Joined:
    Jan 12, 2006
    Messages:
    8,314
    Likes Received:
    70
    Location:
    Tasmania
    Checking it out now... thx :)
     

Share This Page