www.webdeveloper.com
Results 1 to 2 of 2

Thread: [RESOLVED] Javascript not displaying XML in IE

  1. #1

    resolved [RESOLVED] Javascript not displaying XML in IE

    Hi people!

    The problem lies in my Javascript but its a XML focus issue. Im displaying some data from a XML sheet on my webpage. parsing it using javascript ofcourse. Now its working in all browsers except IE.

    I understand that Ie handles xml different to other browsers and iv wirrten that into my code. my issue is that the data im trying to loop through is not the firstchild of my root node.

    Very confusing to read i no... so here is my code...u will get the idea!

    Thanks in advance!!

    Javascript:

    Code:
     <script type="text/javascript">
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xmlhttp.open("GET","data.xml",false);
    xmlhttp.send();
    xmlDoc=xmlhttp.responseXML;
    
    var x=xmlDoc.getElementsByTagName("homepage");
    for (i=0;i<x.length;i++)
      {
      document.write("<div class='item left'><span class='name'>");
      document.write(x[i].getElementsByTagName("name")[0].childNodes[0].nodeValue);
      document.write("</span><img src='images/products/candles.jpg' class='img' alt='Candles' /><span class='price'>&pound;");
      document.write(x[i].getElementsByTagName("price")[0].childNodes[0].nodeValue);
      document.write("</span><a href='#'><img src='images/view_item.gif' class='img' alt='View Item' /></a></div>");
      }
    </script>
    and XML:
    Code:
    <root>
    	<homepage>
    		<homepageitem>
    			<name>Floating Candle</name>
    			<image>candles.jpg</image>
    			<price>32.50</price>
    			<link>#1</link>
    			<desc>Insert description here LOL</desc>
    			<image2></image2>
    			<image3></image3>
    			<image4></image4>
    			<image5></image5>
    			<image6></image6>
    		</homepageitem>
    		<homepageitem>
    			<name>Waterford Perfume</name>
    			<image>perfume.jpg</image>
    			<price>10.99</price>
    			<link>#2</link>
    			<desc>Insert description here LOL</desc>
    			<image2></image2>
    			<image3></image3>
    			<image4></image4>
    			<image5></image5>
    			<image6></image6>
    		</homepageitem>
    		<homepageitem>
    			<name>Cake Topper</name>
    			<image>cake_top.jpg</image>
    			<price>12.50</price>
    			<link>#3</link>
    			<desc>Insert description here LOL</desc>
    			<image2></image2>
    			<image3></image3>
    			<image4></image4>
    			<image5></image5>
    			<image6></image6>
    		</homepageitem>
    	</homepage>
    </root>
    If any1 has any ideas i would really appreciate it!!

    Edit: I thought i may be able to fix it by changing
    Code:
    xmlDoc.getElementsByTagName("homepage");
    into:
    Code:
    homepage.getElementsByTagName("homepage");
    so that it only looks at homepageitem inside homepage...but that seemed to break the whole thing?
    Mike Oram
    Elite Web-Creation
    Design Innovation Guaranteed
    www.eliteweb-creation.co.uk

  2. #2

    resolved Resolved

    Okay so iv just uploaded my site to my server and its working in ie now?! it would seem that the way ie processes the XML requires serverside processing as it works online. It also works offline when i run it through my apache server. (which i wasnt doing b4) so seems to be resolved! thanks anyway!
    Mike Oram
    Elite Web-Creation
    Design Innovation Guaranteed
    www.eliteweb-creation.co.uk

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles