load XML with javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • basha9
    New Member
    • Aug 2007
    • 4

    #1

    load XML with javascript

    Hi everybody ,

    Can u tell me how to load .xml file from javascript in IE.If u can provide the code it's very greatefull to u..


    ---Tq.
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    hi ...

    i splitted your post from the thread you posted it in ... because it covers a new topic ... please don't misuse one thread for different questions.

    kind regards

    Comment

    • basha9
      New Member
      • Aug 2007
      • 4

      #3
      Loading .xml file, problem in Ie

      Hi everybody can anybody give me the solution what to do and all.
      I am having problem that loading .xml file from the javascript that is ok in mozilla where as in ie doesn't work properly. So, can plz help to solve this..

      This is my code:
      Save as labels.html
      -----------------------------
      [HTML]<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
      "http://www.w3.org/TR/html4/strict.dtd">
      <html>
      <head>
      <meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type">
      <title>Addres s book</title>
      <script type="applicati on/javascript">
      var ELEMENT_NODE = 1
      //TEXT_NODE

      function loadAddresses()
      {
      xmlDoc = document.implem entation.create Document("", "", null);
      xmlDoc.onload = writeList;
      xmlDoc.load("la bels.xml");
      }

      function writeList()
      {
      var labels = xmlDoc.getEleme ntsByTagName('l abel');
      var a1 = new Array();
      var ol = document.create Element('OL');

      for (i=0; i < labels.length; i++)
      {
      var li = document.create Element('LI');
      alert(""+labels[i].getAttribute(' name'));
      a1[i] =labels[i].getAttribute(' name')
      var cardimg = document.create TextNode(
      labels[i].getAttribute(' name') +',' );
      var cardpos = document.create TextNode(
      labels[i].getAttribute(' pos'));
      li.appendChild( cardimg);
      li.appendChild( cardpos);
      ol.appendChild( li);

      }

      document.getEle mentById('updat eTarget').appen dChild(ol);

      }


      </script>
      </head>
      <body id='updateTarge t'>
      <p>
      <a href="javascrip t:loadAddresses ()">Click here to load addresses</a>
      </p>
      </body>
      </html>[/HTML]
      ---------------------------------------

      Save as lables.xml
      ----------------------------

      [CODE=xml]<?xml version="1.0" encoding="iso-8859-1"?>
      <labels>
      <label name='c1.gif' pos="1"> </label>
      <label name='c2.gif' pos="2"> </label>
      <label name='c3.gif' pos="3"> </label>
      <label name='c4.gif' pos="4"> </label>
      </labels>[/CODE]
      Last edited by gits; Aug 27 '07, 01:55 PM. Reason: added CODE tags

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        threads merged ...

        have a look at the following http://www.w3schools.com/dom/loadxmldoc.asp
        that should help you ;)

        kind regards

        Comment

        • epots9
          Recognized Expert Top Contributor
          • May 2007
          • 1352

          #5
          You're missing the code for ie (tutorial), take a look at the example cuz right now you only have it set up to work in anything but ie.

          Comment

          Working...