Results 1 to 3 of 3

Thread: XML code in HTML not working in IE

  1. #1
    Join Date
    Nov 2010
    Posts
    28
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Question XML code in HTML not working in IE

    I'm not sure where the XML forum is, but maybe this will do. It's actually a combination of HTML, XML, and JavaScript. But anyway...

    I am new XML, and need a little help getting it to work in IE—my code below already works in Firefox and Opera (I haven’t checked Chrome or Safari yet). For the following simple XML file:

    HTML Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <location>
      <california>
        <cityname>Oakland</cityname>
        <description>Located east of San Francisco on San Francisco Bay</description>
      </california>
    </location>
    And for the following JavaScript parsing code:

    HTML 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","test.xml",false);
    xmlhttp.send();
    xmlDoc=xmlhttp.responseXML; 
    
    document.write("<table border='1'>");
    var x=xmlDoc.getElementsByTagName("california");
    for (i=0;i<x.length;i++)
      {
      document.write("<tr><td>");
      document.write(x[i].getElementsByTagName("cityname")[0].childNodes[0].nodeValue);
      document.write("</td><td>");
      document.write(x[i].getElementsByTagName("description")[0].childNodes[0].nodeValue);
      document.write("</td></tr>");
      }
    document.write("</table>");
    </script>
    How do I get my XML file to display in IE? Are there any basic inconsistencies or errors in my code that I have not noticed which is why IE fails to show what Firefox does? Thanks.

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    you should ask a mod to move this to the javascript forum.

    I don't know much about dealing with xml in javascript, but I would suspect this is a shortcoming of the browser. IE doesn't handle xml well at all. Do you have access to a server-side language like php? It would be simpler to parse the xml into html before it is output via ajax.

  3. #3
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

Bookmarks

Posting Permissions

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